The C# 2.0 Language - What’s New (Part I)

Posted by: Suprotim Agarwal , on 3/11/2007, in Category C# 2.0, 3.0 and 4.0
Views: 45872
Abstract: C# was created by Microsoft as a major part of its .NET initiative. C# is a modern, powerful, component-orientated, flexible, safe, internet friendly and an easy to use language that takes advantage of virtually any feature in this platform. Well people familiar with C# 1.1 know that. This article is a two part series. Let us explore what’s new in C# 2.0
Introducing C# 2.0
 
With the release of Visual Studio 2005 (formerly codenamed Whidbey), C# is back with some new innovations. The C# language has been updated to version 2.0 and comes with several language extensions which we will explore in this 2 part series article. Besides Generic types, the C# language introduces some other interesting features such as Iterators, Partial Classes and Anonymous methods, which are briefly mentioned below.
Generics
Although new to the .NET platform, this concept has been around for years. Generics is a term used to describe generic types. It greatly enhances application performance and type safety and allows you to write highly general, flexible and safe code. It permits classes, interfaces, structs, delegates and methods to be parameterized by the types of data they store and manipulate.
Iterators
Iterators specify how a for-each loop will iterate over a collection and return its internal items. They allow you to create enumerable classes with minimum coding.
Partial Classes
Partial Classes allows you to split a single type, like your class, across more than one file (.cs). They are useful if you have extremely large, unwieldy types.
Nullable Types
Nullable types allow a variable to contain a value that is undefined. This is useful when working with databases where the value returned might be null
Anonymous Methods
Anonymous Methods Are Inline Delegates. It enables you to pass a block of code as a parameter. Anonymous methods enables you to directly associate a block of code statements to a given event. You use them anywhere a delegate is used . So there is no need to define a new method.
Namespace alias qualifier
C# 2.0 adds the namespace alias qualifier, the :: operator, to provide more control over accessing namespace members.
Static Classes
With C# 2.0, now you also can declare classes as static. This signals the compiler that this class should not be instantiated and can only contains static members.
Property Accessor Accessibility
C# 2.0 allows a fine control over the accessibility of accessors and indexers within a property.
Covariance and Contravariance in Delegates
The method passed to a delegate may now have greater flexibility in its return type and parameters.
 
Conclusion
In this article, we explored the various new features introduced in C# 2.0. In Part two, we will explore these new features in detail.
Give me a +1 if you think it was a good article. Thanks!
Recommended Articles
Suprotim Agarwal, ASP.NET Architecture MVP, MCSD, MCAD, MCDBA, MCSE, is the CEO of A2Z Knowledge Visuals Pvt. He primarily works as an Architect Consultant and provides consultancy on how to design and develop .NET centric database solutions.

Suprotim is the founder and primary contributor to DotNetCurry, SQLServerCurry and DevCurry. He has also written an EBook 51 Recipes using jQuery with ASP.NET Controls.

Follow him on twitter @suprotimagarwal




Page copy protected against web site content infringement by Copyscape


User Feedback
Comment posted by kamal on Saturday, September 08, 2007 2:01 AM
By the above information i got some idea about c# 2.o.
I want differences between c#.Net,vb.NET&asp.NET
please send information about these
Comment posted by suprotim on Thursday, September 20, 2007 7:38 AM
Check this link for differences between vb.net and C#

http://www.codeproject.com/dotnet/vbnet_c__difference.asp
Comment posted by moheed_dotnet on Monday, April 07, 2008 11:33 AM
need to expand the topics and give some good examples also.
Comment posted by Muthu on Saturday, June 21, 2008 10:44 AM
faq
Comment posted by g on Wednesday, July 09, 2008 3:03 AM
f
Comment posted by prashant on Tuesday, October 07, 2008 11:37 AM
What are the facts and figures about job opportunities in .Net Vs Java?
Comment posted by Siddartha12002 on Friday, December 05, 2008 4:00 AM
Thanx

Post your comment
Name:  
E-mail: (Will not be displayed)
Comment:
Insert Cancel