www.MasterCsharp.com Logo  AksTech Ad
 Welcome to MasterCSharp.com - Master C#, the easy way... - by Saurabh Nandu

 

 

Introduction to C# (C Sharp)
   
 

 

[Rate this Article]
Motivation
During the past few months while I have been on the Internet after I started up this site, many people have popped up the question to me, What is C#? To spare me the trouble of replying to each and everyone (which I usually do ..) I decided to put my head into a article which answers the question.

.NET Platform
Today software technology has come a long way from what anyone might have imagined 5 years back. Internet has been able to connect to people all around the world helping them to communicate and work together despite the geographical boundaries. Today everyone's talking about convergence, e-commerce and other such terms which have evolved with the evolution on the Internet. Benefits of Internet is well known to you all as consumers, but the hardships faced by the programmers who have to program for such diverse environment is known to few.

The enterprise setup's today need to have n-tire architecture with diverse platforms and object models communicating with each other. The size of applications has also multiplied and developers need to develop applications which can be accessed from any platform (like Windows, Linux, Mac , Unix etc) and which consist of components written in many programming languages and object models.
For people who are developing such applications its a Hell out there! Since most of the programming languages used today have been written 5 to 10 years back, when the language vendors did not know the problems that would be faced by the current situation. Many language vendors have tried to upgrade their languages, but there is a limit to which they have been successful since they have to maintain backward capability and face many other problems too.
Due to this new Object - Oriented languages like Java have been a obvious choice of many developers since it has edge over the previous languages. Microsoft has recognized this, and is aware that there is a need for a new Microsoft technology which will help developers spend more time actually developing huge applications rather than sit debugging it!

To solve the woe's of the current programmers Microsoft has come with a very promising solution. The .NET Platform.
.NET, is a platform; by this I mean its sort of a runtime environment but much more bigger (in size too :) ) on which applications coded in any of the managed languages run. The .NET runtime environment acts as software layer between the applications written on the .NET and the operating system (or hardware). This is what actually gives programs written on .NET, Java like functionality of write once and execute anywhere subject to the fact that you have the .NET runtime system installed for your platform and CPU.
As I said .NET acts software abstraction between your .NET Programs ( Managed Code ) and the hardware, to run Managed Code the .NET runtime has a Just-In-Time (JIT) compiler which JIT's the Managed code into Native code at runtime. Remember that .NET Platform always compiles the code unlike Java which interprets the code during runtime.
Also the .NET platform supports a variety of languages like C#, VB.NET , Managed C++ which are being developed by Microsoft, 22 other languages like Perl, Python, COBOL etc are also coming up with their compilers for the .NET platform.

Microsoft has addressed the current problems in programming on a fighting foot. It has come up with the CTS (Common Type Specification), which is nothing but a specification of the minimum norms all the languages which are being developed on the .NET platform should support. This guarantees the fact that the code written in any of the CTS compliant languages can be used (extended/inherited) from any other language on the .NET seamlessly. This feature has brought the interoperability issue between languages to a extinction.
Just imagine you convert all your old C++ algorithms to Managed C++ with minimum modification and then you use these algorithms in Visual Basic.NET to create Windows Forms (GUI Application)  application fast and rapidly without a single extra like to convert the code from C++ to VB !!

Second very interesting feature is the death of Memory Management by the developer. All .NET languages are automatically garbage collected, so Bye- Bye to all those Memory Leaks, the .NET garbage collector does all the memory management job for you. Hence applications on the .NET Platform are called Managed Applications.
There are many other features which I will discuss some time later and are out of the scope of this article.

C#
According to Microsoft C# is, "C# is a simple, modern, object oriented, and type-safe programming language derived from C and C++. C# (pronounced "C sharp") is firmly planted in the C and C++ family tree of languages, and will immediately be familiar to C and C++ programmers. C# aims to combine the high productivity of Visual Basic and the raw power of C++."

Basically, C# is the premier language being promoted by Microsoft for the .NET Platform. C# has been created by Anders Heljsberg, famous for creating the Turbo Pascal Compiler and the leader of the team that designed Delphi, and Scott Wiltamuth from Microsoft.
C# has been designed to provide optimum blend of simplicity, performance and creativity to leverage the power of the .NET Platform. A huge portion of the .NET Framework library has been coded in C#. C# was developed specifically for the .NET Platform and hence it leverages the .NET Platform features to the Max. C# is not a upgrade to C++, its totally a new object - oriented language. It is being truly promoted by Microsoft that, "C# has the power of C++ and ease of VB".

Some of the features of C# are:
1) Simple
2) Modern
3) Object - Oriented
4) Type Safe
5) Versionable
6) Maintainable
7) Interoperable

1) Simple
My nightmares of pointers in C / C++ are still alive! I can never remember when to use "::" or when to use "->" operator. C# has simply done away with with pointers, this makes life much simple for the programmer. Also since its on .NET Platform, it inherits the feature of automatic memory management and garbage collection.
Also varying rages of the primitive types like Integer, Floats etc according to the processor is no longer a problem. Your integer data-type Int16 will always be of 16 bits and Int32 will always be 32 bits no matter which processor or operating system you are on.

Integer values of 0 and 1 are no longer accepted as Boolean values. Boolean values are pure True or False values in C#. Hence in your loops and condition checking expressions should evaluate to Boolean values only. Also the operators have been made safe, so no more errors of assignment (= operator) when you want to actually what to check you conditions (== operator) can occur.
Microsoft has taken a long analysis of the common mistakes made by programmers and tried to provide a solution for it in C#.
Example:
Infinite loops like below will generate a compiler error, since in C# you cannot convert implicitly between Integer and Boolean.

int i=1 ;
while(i) //Compiler Error
{
......
.........
}

Also the below condition checking expression will produce a error at compile time , since you are trying to assign a value instead of making a comparison.

int i=6;
int j=8 ;
if(i=j) //Compiler Error
{
.......
........
}

So now you have to use the "= =" operator for comparison and the "=" operator for assignment.

2) Modern
As I have explained in my introduction to the .NET platform, the existing languages have been developed say 5 to 10 years back and lack the concepts to meet the modern day requirements. On the other hand C# has been based according to the current trend and is very powerful and simple for building interoperable, scalable applications. Features like events, error handling make programming GUI's easy. Also a new Decimal Type has been introduced in C# to take care of all those precise financial calculations.

3) Object - Oriented
Over the years we have seen a change in many programming models from structural, to procedural, to modular and finally the Object - Oriented Model. The Object - Oriented model has been based on how objects in the real world interact. C# is a fully Object - Oriented Language as against C++ which though called as Object Oriented allows other object models also.
The gains of using a Object Oriented model are well known. In C# the Type contains everything and is the building block of any program. Data Encapsulation , inheritance , polymorphism are supported by C#. Although C# only supports single inheritance, multiple inheritance of interfaces is possible.
Unlike Java in which primitive types (int, float, double) are Not objects, C# has introduced Structures (Structs) which enable the primitive types to become full fledged objects discarding the use of wrapper classes of Java! Hence something like below is possible:

class TestObject{
public static void Main()
{
  int i =3 ;  //Declare a integer
  string s = i.ToString(); //Convert the primitive type to String type also called a Boxing
  Console.WriteLine(s) ; //Print the value of s
  Console.WriteLine(45.ToString()); //Directly Box the constant (45) to string
}
}

4) Type Safe
 All Variables in C# are type safe. By Type Safety I mean that you cannot perform unsafe casts like convert a Double to a Boolean. All variables have to be properly initialized before use or the compiler will complain. Value Types (primitive types/structures/enums) are initialized to Zero and Reference types (objects and classes) are initialized to Null by the compiler automatically.
Arrays are zero base indexed and are bound checked. Overflow of types can be checked in C# too. Hence, say if a Int16 variable is assigned a value greater than its range, you can set the compiler to generate a error instead of silently letting the variable being set to a wrong value and causing problems in your code later.
Also the Switch / Case statements don't allow fall through any more!

5) Versionable
Programmers of on the Windows platform are well, aware of the "Dll Hell". It is caused when, some program updates a shared library, which causes the current application to crash. In C# you can Version your Dll's so that your application is compatible with new versions of the Dll and the runtime always loads the correct version of the library required by the application. Different versions of the same Dll can execute at the same time , this is called side by side execution.

6) Maintainable
.NET has introduced assemblies which are self-describing and do not need to be registered anywhere. Hence in the case you want to upgrade your application its as simple as deleting the old files and updating them with new ones. You no longer have to go through the tedious process of registering all your dll's .

7) Interoperability
Another significant gain C# gets from the .NET Platform is, interoperability of code. Even though C# does not support pointers, you can used them as unsafe code blocks to interop with your old code. COM components can also be easily invoked from C#. Components from VB.NET and other Managed code languages and directly be used in C#.

Conclusion
Due to these and many other rich features C# is one of the promising languages built for the future. All those people doubting the power and feature of this language should shed their fear about C#. Its better to lead the band wagon rather than run behind it later :).
Interested in starting up with C#? Read this article to install the .NET SDK v1.1 and this article to get started writing your own C# programs.

 

  
Saurabh Nandu - 08 March 2001


Your Ratings / Comments
     
 

[Go to Top]

How many cups of coffee is this article worth??

Rating (Bad)-(Excellent)

Your Name
Your E-mail  
Your Message (Optional)

Viewer Ratings/Comments
Rating Description
2 - Deepak on 7/18/2001 9:27:00 PM
4 - Tokunboh Odusami on 8/17/2001 2:02:00 PM
3 ok - Sohail Shazad on 9/5/2001 7:52:00 AM
5 Maney Thanks - Ron Mahon on 10/5/2001 7:16:00 AM
1 - kiran on 11/16/2001 3:49:00 PM
5 - Tamir Berger on 12/10/2001 3:51:00 AM
3 - gf on 3/23/2002 6:26:00 PM
Just Comments - cao dinh dung on 6/9/2002 12:24:00 AM
4 - nguyen van linh on 6/10/2002 2:21:00 AM
1 - Dirk on 11/20/2002 9:35:00 AM
1 hai dont have codee - venkatesh on 1/17/2003 3:32:00 AM
2 - sudheer Reddy on 6/14/2003 3:19:00 AM
5 - on 6/18/2003 11:53:00 AM
Just Comments - Ahmed Kamal on 9/4/2003 6:49:00 PM
4 - Wilson Araujo on 10/29/2003 8:03:00 AM
Just Comments zxvc - xc on 4/1/2004 8:09:00 PM
5 - Carlos Figueredo on 10/21/2004 8:57:00 AM
1 Nice one... Thanx! - Diddy on 11/17/2004 11:50:00 PM
3 no message - eve on 2/4/2005 5:41:00 AM
5 - Deepthi on 3/31/2005 3:22:00 AM
3 - Bob on 5/11/2005 1:12:00 PM
4 - jkhdsfkhjk on 1/22/2006 11:18:00 PM
4 I appricate your efforts.....!!!!! - Mukesh on 10/18/2006 5:47:00 AM
3 Great Affort - Vivek on 11/15/2006 1:00:00 PM
3 hi this intor of c # is very well for new user of c# thanks for ur co-operation - bhushan ambhore on 11/21/2006 12:19:00 AM
4 good - murali on 11/21/2006 7:56:00 AM
Just Comments gud code but only theortically,so there should be some coding. - anuj on 12/19/2006 5:13:00 AM
3 Well i need video tutorial i mean little bit practical oriented since i am a programmer myself - Ato on 1/13/2007 7:13:00 AM
3 - manish pandey on 1/22/2007 2:44:00 AM
3 - maya on 2/2/2007 2:45:00 AM
4 very fine article to who know about .net. - vijaya kumar on 2/23/2007 4:28:00 AM
Just Comments please display tutorials and examples on each topic about c sharp language in detail it is very helpful to beginers. - vijaya kumar on 2/23/2007 5:25:00 AM
Just Comments please give me c sharp information - shakti rana on 3/8/2007 7:02:00 AM
3 Good work Saurabh.... - Ravi on 3/16/2007 4:59:00 AM
Just Comments I would like to know more about the C#, i wanted to become a good programmer in C#, i wanted to finish my MCSD Certification. please help me to do that... - yogeshwar on 3/19/2007 2:08:00 AM
3 i would like to know more and more to finish my mcsd certification, please help me to do some projects also using C#... - yogeshwar on 3/19/2007 2:10:00 AM
3 - Neena on 5/4/2007 4:06:00 AM
Just Comments It's good but takes too much time to read. - Ankit Maru on 5/20/2007 10:09:00 AM
4 the article is good enough to get brief idea about introduction to c#. keep it up. - santosh kumar rath on 5/25/2007 11:33:00 PM
5 Ya das ise ine gooten articlen do cunt!, essen mine pillaman. Du hapst shise ine dine copfe, shfine copfe. - Gooten Articlen on 7/9/2007 2:44:00 PM
3 its gud - vishal on 7/12/2007 12:08:00 AM
1 Very Worse - RavindraDasari on 10/14/2007 11:05:00 PM
1 nice gathering very nice and simple points by learing c# - shiva on 2/14/2008 5:28:00 AM
3 it is good and gives a good insight to beginners good effort dude - nitin on 2/17/2008 9:17:00 AM
5 - Karthik on 3/24/2008 10:09:00 AM
1 cxvcxvcxv - cxccx on 5/1/2008 5:48:00 AM
3 EXCELLENT - VIVEK VISHWAKARMA on 5/6/2008 9:52:00 PM
1 I am very eager to learn c#. its very useful for me... - Guna on 8/26/2008 11:59:00 PM
1 fagggggggggggggg u suckkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk - fuck u on 9/8/2008 6:02:00 PM
Just Comments how to learn and download c# - amit on 10/24/2008 6:51:00 AM
Just Comments very very nice i want to be like you. - tanu kour on 10/30/2008 10:08:00 AM
2 I want to download the features of C#. How can I? - Bharathi on 11/23/2008 6:08:00 PM
3 very good needs updating - justin uk on 1/4/2009 4:58:00 PM
5 excellent articles with great view of giving attention towards the need of students this course - Atul Prashant on 1/19/2010 5:09:00 AM
3 - Karthik on 1/24/2010 9:32:00 AM
4 nive one.. - prakash on 4/18/2010 10:31:00 PM

[Go to Top]


 
 
  Copyright © 2002 - 2004 MasterCSharp.com. All rights are reserved.

  Presenting MasterCSharp.com in association with AksTech Solutions - .NET Solutions Development and Consulting. 

  Best Viewed in IE 4.0+ and 800x600 Resolution