What's New in the C# 2.0 Language and Compiler 

With the release of Visual Studio 2005, the C# language has been updated to version 2.0, which supports the following new features:

  • Generics
    Generic types are added to the language to enable programmers to achieve a high level of code reuse and enhanced performance for collection classes. Generic types can differ only by arity. Parameters can also be forced to be specific types. For more information, see Generic Type Parameters.
  • Iterators
    Iterators make it easier to dictate how a foreach loop will iterate over a collection's contents.
  • Partial Classes
    Partial type definitions allow a single type, such as a class, to be split into multiple files. The Visual Studio designer uses this feature to separate its generated code from user code.
  • Nullable Types
    Nullable types allow a variable to contain a value that is undefined. Nullable types are useful when working with databases and other data structures that may contain elements that contain no specific values.
  • Anonymous Methods
    It is now possible to pass a block of code as a parameter. Anywhere a delegate is expected, a code block can be used instead: there is no need to define a new method.
  • Namespace alias qualifier
    The namespace alias qualifier (::) provides more control over accessing namespace members. The global :: alias allows access the root namespace that may be hidden by an entity in your code.
  • Static Classes
    Static classes are a safe and convenient way of declaring a class containing static methods that cannot be instantiated. In C# version 1.2 you would have defined the class constructor as private to prevent the class being instantiated.
  • External Assembly Alias
    Reference different versions of the same component contained in the same assembly with this expanded use of the extern keyword.
  • Fixed Size Buffers
    In an unsafe code block, it is now possible to declare fixed-size structures with embedded arrays.
  • Friend Assemblies
    Assemblies can provide access to non-public types to other assemblies.
  • Inline warning control
    The #pragma warning directive may be used to disable and enable certain compiler warnings.

The C# compiler introduces the following additions and changes for this release:

  • /errorreport option
    Can be used to report internal compiler errors to Microsoft over the Internet.
  • /incremental option
    Has been removed.
  • /langversion option
    Can be used to specify compatibility with a specific version of the language.
  • /moduleassemblyname option
    Allows you to build a .netmodule file and access non-public types in an existing assembly.
  • /pdb option
    Specifies the name and location of the .pdb file.
  • /platform option
    Enables you to target Itanium Family (IPF) and x64 architectures.

See Also

Concepts

C# Programming Guide

Other Resources

C# Language Specification
C# Reference