New features in C# 2.0
1) Partial Types
Partial classes allow you to split a class definition across multiple source files. The benefit of this approach is that it hides details of the class definition so that derived classes can focus on more significant portions The Windows Form class is an example of a built-in partial class. In Visual Studio 2003 and earlier, forms classes included code generated by the form designer. Now that code is hidden in a partial class named form.Designer.vb or form.Designer.cs. When working on large projects, spreading a class over separate files allows multiple programmers to work on it simultaneously. When working with automatically generated source, code can be added to the class without having to recreate the source file.
2) Static Classes
Static classes and class members are used to create data and functions that can be accessed without creating an instance of the class. Static class members can be used to separate data and behavior that is independent of any object identity: the data and functions do not change regardless of what happens to the object. Static classes can be used when there is no data or behavior in the class that depends on object identity.
The main features of a static class are:
§ They only contain static members.
§ They cannot be instantiated.
§ They are sealed.
§ They cannot contain Instance Constructors.
Generics are part of the .NET Framework's type system that allows you to define a type while leaving some details unspecified. Instead of specifying the types of parameters or member classes, you can allow code that uses your type to specify it. This allows consumer code to tailor your type to its own specific needs.
§ Use generic types to maximize code reuse, type safety, and performance.
§ The most common use of generics is to create collection classes.
§ The .NET Framework class library contains several new generic collection classes in the System.Collections.Generic namespace. These should be used whenever possible in place of classes such as ArrayList in the System.Collections namespace.
4) Nullable types and the null coalescing operator
Nullable types are instances of Nullable structure. This Nullable structure is a generic struct type in base class library. It behaves like value type when it has a value which means that boxing or unboxing occurs. However when it does not have a value, it is null instead of the value types default value, and boxind or unboxing does not occur.
C# provides language support for nullable types using a question mark as a suffix.
For example, int? is the same type as Nullable<int>
One of the cool language features of C# is the ?? "null coalescing" operator. This provides a nice way to check whether a value is null, and if so return an alternate value.
One interesting new feature of the C# 2.0 is the "yield" keyword. Basically it is used to iterate through objects returned by a method.Used in an iterator block to provide a value to the enumerator object or to signal the end of iteration The yield statement can only appear inside an iterator block, which might be used as a body of a method, operator, or accessor. The body of such methods, operators, or accessors is controlled by the following restrictions:
§ Unsafe blocks are not allowed.
§ Parameters to the method, operator, or accessor cannot be ref or out.