What's New in C# 2.0

来源:互联网 发布:java 释放mysql连接池 编辑:程序博客网 时间:2024/04/30 12:40

With the release of Visual Studio 2005, the C# language has been updated to version 2.0.

Generics (C#)

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. See Generic Type Parameters (C#) for more information.
Iterators (C#)

Iterators make it easier to dictate how a foreach loop will iterate over a collection's contents.
Partial Class Definitions (C#)

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 (C#)

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.
:: Operator

The namespace alias qualifier (::) provides more control over accessing namespace members. The How to: Use the Global Namespace Qualifier (C#) 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# v1.2 you would have defined the class constructor as private to prevent the class being instantiated.
extern (C# Programmer's Reference)

Reference different versions of the same component contained in the same assembly with this expanded use of the extern keyboard.
Accessor Accessibility

It is now possible to define different levels of accessibility for the get and set accessors on properties.
Covariance and Contravariance (C#)

The method passed to a delegate may now have greater flexibility in its return type and parameters.
Fixed Size Buffers (C#)

In an unsafe code block, it's now possible to declare fixed-size structures with embedded arrays.
Friend Assemblies (C#)

Assemblies can provide access to non-public types to other assemblies.
#pragma warning

The #pragma warning directive may be used to disable and enable certain compiler warnings.