Generics, nullable value types, iterators and partial types.
This release added 12 features, each with a before-and-after example.
Features in C# 2.0
- Anonymous methods - Create a delegate using an inline function body.
- Delegate covariance and contravariance - Allow a delegate to point at a method whose parameters or return type are less or more derived than the delegate's signature.
- Extern alias - Disambiguate types with the same fully-qualified name from different assemblies.
- Friend assemblies - Use
InternalsVisibleToto exposeinternalmembers to specific assemblies. - Generics - Write type-safe code that works with multiple data types.
- Iterators - Produce and consume sequences.
- Null-coalescing operator - Provide a default value when an expression is null.
- Nullable value types - Give value-types "null" semantics to indicate missing values.
- Partial types - Split type definitions between files to separate generated and human-written code.
- Pragma directives - Use
#pragma warningto selectively suppress or restore compiler warnings. - Property accessor accessibility - Specify different access modifiers on a property's
getandsetaccessors. - Static classes - Declare a class as
staticto prevent instantiation and ensure only static members.