About C# 3.0

An objective of this book is to present C# in its very best style. The version we are using is C# 3.0 on the .NET 3.5 Beta 2 Framework (August 2007).

C# 1.0 came out in December 2002, embodying much of the research in OOP that had taken place since Java was launched seven years previously. C# 2.0 was released in final form in September 2005, and the ECMA standard was made available in June 2006. C# 2.0 added five significant features to C# 1.0, most of which are used in the patterns in this book:

  • Generics that allow classes, structs, interfaces, delegates, and methods to be parameterized by the types of data they store and manipulate

  • Anonymous methods that allow code blocks to be written "inline" where delegate values are expected

  • Iterators, which are methods to incrementally compute and yield sequences of values

  • Partial types that allow classes, structs, and interfaces to be broken into multiple pieces stored in different source files for easier development and maintenance

  • Nullable types that represent values that possibly are unknown; they support all possible values of an underlying type plus an additional null state

Within Microsoft, work continued on the language, with a particular emphasis on the integration of SQL database interfacing and the associated dynamic typing required. The report on Version 3.0 of the language, finalized in May 2006, includes substantial advances in integrating the functional and database programming paradigms into mainline object-orientation:

  • Implicit typing of local variables, which permits the types of local variables to be inferred from the expressions used to initialize them

  • Extension methods, which make it possible to extend existing types and constructed types with additional methods, outside their definitions

  • Lambda expressions, an evolution of anonymous methods that provide improved type inference and conversions to both delegate types and expression trees

  • Object initializers, which ease construction and initialization of objects

  • Anonymous types, which are tuple types automatically inferred and created from object initializers

  • Implicit typing of arrays, which is a form of array creation and initialization together where the element type of the array is inferred from the initializer

  • Query expressions, which provide a language-integrated syntax for queries that is similar to relational and hierarchical query languages, such as SQL and XQuery

All these new features are used in a natural way in this book. For full details on the entire C# 3.0 language, see the reference documentation available at http://msdn2.microsoft.com/vcsharp.

Get C# 3.0 Design Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.