Monday, May 9, 2011

C# Features

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 enable 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.

No comments:

Post a Comment