C#.NET Programming
C#.NET Getting Started
By Hafeez Mohammed
Introduction
C# (pronounced C sharp) can be defined as a simple,
modern, object oriented, and type-safe programming language derived from C and
C++. C# aims to combine the high productivity of Visual Basic and the raw power of
C++."
C# is a simple but powerful programming language intended for writing
enterprise applications.
The C# language is an evolution of C and C++. It uses many C++ features in
the areas of statements, expressions, and operators.
C# introduces considerable improvement and innovations in areas such as type
safety, versioning, events, and garbage collection.
C# provides access to the common API styles: .NET Framework, COM, Automation,
and C-style APIs. It also supports unsafe ("The unsafe keyword denotes an unsafe context, which is required for any
operation involving pointers") mode, where you can
use pointers to manipulate memory that is not under the control of the garbage
collector.
Why use C#.NET
C# is an elegant, simple, type-safe, object-oriented language that allows
enterprise programmers to build a breadth of applications.
C# also gives you the capability to build durable system-level components by
virtue of the following features:
- Full COM/Platform support for existing code integration.
- Robustness through garbage collection and type safety.
- Security provided through intrinsic code trust mechanisms.
- Full support of extensible metadata concepts.
You can also interoperate with other languages, across platforms, with legacy
data, by virtue of the following features:
- Full interoperability support through COM+ 1.0 and .NET Framework services
with tight library-based access.
- XML support for wWeb-based component interaction.
- Versioning to provide ease of administration and deployment.
C#.NET will be big business.
So What is C# Anyway
Now this .NET Framework essentially sits on top of the operating system. And it handles everything from memory management to rendering a user interface.
When you program in C#.NET, you're dealing with this framework thing. And that framework thing brings with it a bunch of 'classes' that provide you with a heap of functionality – from a function to reverse a string through to procedures that really take you to the heart of the operating system, perhaps procedures that had never before been available to VB developers.
In addition, the framework allows you to forget about memory management. It's incredibly scalable and even brings an end to the infamous 'DLL Hell' by getting rid of GUIDs, registration and all that automatically.
It's the framework that allows you to create in C#.NET everything from DOS-style console applications through to Web sites – in just the same way as you would any regular desktop application!
But what is this framework? Is it a program? Is it an operating system? What?
It's actually all of those things. It's an 'upgrade' if you like – an add-on to Windows. It's incredibly useful and it will soon be bundled by default with every Microsoft operating system. In the meantime, you'll find it on the Windows Component Update CD that ships with Visual Studio.NET.
Remember– you need the .NET Framework before you can run any program created in a .NET language.
Let me guess what you are thinking!
Which is better VB.NET or C#.NET?
Every .NET language code gets compiled to IL code (Intermediate Language or MSIL)
which then runs on the .NET Platform. Infact all languages on the .NET produce
the same IL code. It does not matter if you use VB.NET, C#,
COBOL.NET, Perl.NET or any other language on the .NET they ALL PRODUCE THE
SAME IL CODE. So now on the .NET all languages have the same efficiency and
power. Its just the developers choice to choose the language whose syntax he is
most comfortable with.
Is C# better than Java?
The argument of C# vs Java has no base, its like debating on why you like apples while I like oranges! but since the question had arised here's my 2 cents on which is better.
The main debate should be between the .NET Platform and the Sun Java VM (virtual
machine). All languages on the .NET gain their powers from the .NET
Platform.
If you stay in touch with the news then you would know that it was
Microsoft who had made the fastest Java VM. They could achieve it by
tweaking the VM to give a better performance over Intel platforms. Although due
to the legal problems this project along with the VJ++ project has been
discontinued.
Just to tell you how serious Microsoft is about the .NET Platform,
they have spent 4 billion dollars and more in the research and development of
.NET and have pledged to devote 80% of their R&D in the year 2001-02 on the
.NET Platform.
We have already see how Microsoft has ambitiously taken over the
market in the past when Windows gained popularity over Macintosh (which people
still think is a superior OS). Also the Netscape and IE war was won by Microsoft
despite Microsoft's late entry into the browser market.
When such a ambitious
company is spending so much resources it sure has to have a strong strategy and
product!
Microsoft had developed the fastest Java VM
which reports say is 5x faster than the Sun VM. They have learned a lot from
their previous ventures. The Sun Java VM does not perform any CPU specific
optimizations. Although I have heard about the new HotSpot VM from Sun, but its
just a code caching mechanism.
Microsoft on the other hand is perusing much
ahead in the CPU specific optimizations. Be sure these optimizations are made to
the JITer and has not effect on the code you compile and this does not make your
code Platform Dependent. What these optimizations do? Say Microsoft finds that a
particular instruction performed on a Intel P-III gives a higher performance and
the same instruction should be performed in a different way on a AMD Durathon,
it tweaks the JIT'er for the specific CPU so that it optimizes the performance
of your applications according to your CPU. Such optimizations helps you to
utilize the true power of the CPU.
If you go the Java way, a Java program
would more or less perform the same on a Intel 1hz or a AMD 1hz without taking
into consideration the special features of the CPU. The .NET Platform will
provide different JIT'ers for the Intel as well as AMD CPU's so that it can
utilize all the special instruction sets which the 2 CPU's have allowing you to
realize the value of the money you have invested in buying a specific
processor.
Is C#, C+++ ( a new version of C++)?
C# is not a upgrade to C++. C# is a totally
new Object oriented programming language. You could say its much more easier and
Object oriented than C/ C++.
Where do I go to get C# Compiler?
The C# compiler is not distributed as a
separate entity yet. You will need to download the .NET SDK (131 Mb) from http://msdn.microsoft.com/net . The SDK contains the C#,
VB.NET, JScript Compilers and full documentation and its Free for
download.
How easy is it to learn C#?
If you are a Java programmer then you will
find it very easy to migrate to C#. Also if you
are a C / C++ programmer then you will find much similar syntax of C#.
Is C# Platform Independant?
C# applications cannot run without the .NET runtime. At present the .NET platform
has been released for Win98/ME and Win NT/2000/XP. Microsoft plans to release
the .NET runtime for other platforms soon. Now if, a .NET runtime has been
released for your platform then all the .NET programs will run on your platform.
This is quite similar to the working of SUN Java which is considered to be
Platform Independent. In the case of Sun Java you need to install a Java Virtual
Machine on your Platform to run Java programs. If your platform does not have a
Java VM then it cannot run Java programs. So, conceptually
Java VM is similar to the .NET Runtime Environment(not literally though).