MSDN Documentation

.NET Framework

New Features in .NET Framework 2.0

The .NET Framework 2.0 introduced a significant number of enhancements and new capabilities for developers. This release focused on improving developer productivity, application performance, and platform robustness. Here are some of the key new features:

Generics

Generics provide a way to create strongly-typed collections and classes without sacrificing type safety or runtime performance. They allow you to define types that operate on elements of a specified type, deferring the specification of that type until the time of instantiation. This reduces the need for casting and improves code readability and performance.

Benefits:

  • Type safety at compile time.
  • Improved performance by avoiding boxing/unboxing.
  • Code reusability.

Example:

System.Collections.Generic.List<string> names = new System.Collections.Generic.List<string>();
names.Add("Alice");
names.Add("Bob");
// names.Add(123); // This would cause a compile-time error

Partial Classes and Methods

Partial classes allow you to split the definition of a class, struct, or interface across multiple files. This is particularly useful for code generation scenarios where generated code can be placed in one file and user-written code in another, without the generated code overwriting user modifications. Partial methods enable a method declaration to be implemented separately, allowing for optional implementation.

Use Cases:

  • Separating designer-generated code from user code.
  • Large classes that are easier to manage when split.

Anonymous Methods and Lambda Expressions

Anonymous methods (and later, lambda expressions in C# 3.0, which builds upon this) allow you to create inline code blocks that can be passed as delegates. This simplifies the creation of event handlers and other delegate-based scenarios. Lambda expressions offer a more concise syntax for creating anonymous methods.

Example (Anonymous Method):

Action<string> greet = delegate(string name)
{
    Console.WriteLine("Hello, " + name);
};
greet("World");

Nullable Value Types

Nullable value types allow you to assign a null value to value types (like `int`, `bool`, `structs`). This is achieved by using the `Nullable<T>` structure or its syntactic sugar `T?`. This is crucial for scenarios where a value might be absent, such as database fields that can be empty.

Example:

int? nullableInt = null;
if (nullableInt.HasValue)
{
    Console.WriteLine(nullableInt.Value);
}
else
{
    Console.WriteLine("Value is null.");
}

Improved Data Access (ADO.NET Enhancements)

.NET Framework 2.0 brought several enhancements to ADO.NET, including:

  • DataSets as XML Schemas: `DataSet` objects can now generate and consume XML Schema Definition (XSD) files, facilitating data interoperability.
  • RowState and RowVersion: Improved tracking of row states and versions within `DataTable` objects for better concurrency control.
  • Typed DataSets: Generated `DataSet`, `DataTable`, `DataRow`, and `DataColumn` objects with strongly-typed accessors, improving compile-time checking and IntelliSense.

ASP.NET 2.0 Features

ASP.NET 2.0, a significant part of the .NET Framework 2.0 release, introduced major advancements:

  • Master Pages: A templating system that allows you to define a consistent layout for multiple web pages, separating design from content.
  • Themes and Skins: A robust theming engine to easily change the look and feel of your web applications.
  • Membership, Roles, and Profiles: Built-in infrastructure for user authentication, authorization, and personalization.
  • Site Navigation: Declarative site map provider and controls for building navigation menus.
  • Web Parts: A framework for building dynamic and customizable user interfaces, allowing users to personalize their portal-like experiences.
  • Data Source Controls: Declarative controls that abstract data access, simplifying the binding of data to UI controls.

Common Language Runtime (CLR) Improvements

The CLR received several updates, including:

  • Improved Performance: Enhancements to the Just-In-Time (JIT) compiler and garbage collector.
  • Application Domains: More robust isolation and management of application domains.
  • Security: Refinements to the Code Access Security (CAS) model.

Managed Providers for Oracle and SQL Server

New managed data providers for Oracle were introduced, enhancing database connectivity options within the .NET Framework.

These features, among others, made .NET Framework 2.0 a foundational release that significantly advanced the .NET platform and provided developers with powerful tools for building sophisticated applications.