DotNetCurry Logo

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

Posted by: Suprotim Agarwal , on 3/11/2007, in Category C#
Views: 52934
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.
Was this article worth reading? Share it with fellow developers too. Thanks!
Share on LinkedIn
Share on Google+
Further Reading - Articles You May Like!
Author
Suprotim Agarwal, MCSD, MCAD, MCDBA, MCSE, is the founder of DotNetCurry, DNC Magazine for Developers, SQLServerCurry and DevCurry. He has also authored a couple of books 51 Recipes using jQuery with ASP.NET Controls and a new one recently at The Absolutely Awesome jQuery CookBook.

Suprotim has received the prestigious Microsoft MVP award for nine times in a row now. In a professional capacity, he is the CEO of A2Z Knowledge Visuals Pvt Ltd, a digital group that represents premium web sites and digital publications comprising of Professional web, windows, mobile and cloud developers, technical managers, and architects.

Get in touch with him on Twitter @suprotimagarwal, LinkedIn or befriend him on Facebook



Page copy protected against web site content infringement 	by Copyscape




Feedback - Leave us some adulation, criticism and everything in between!
Comment posted by kamal on Saturday, September 8, 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 7, 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 9, 2008 3:03 AM
f
Comment posted by prashant on Tuesday, October 7, 2008 11:37 AM
What are the facts and figures about job opportunities in .Net Vs Java?
Comment posted by Siddartha12002 on Friday, December 5, 2008 4:00 AM
Thanx