Saturday, November 18, 2006

 

New Features in C# 3.0

The C# 3.0 language enhancements are part of the LINQ project, whose aim is to make working with data as easy as working with objects. This will be a major evolutionary step forward in Microsoft’s development landscape (John Lam’s recent addition to the Microsoft stable could also be seen as a push in this direction). LINQ provides a single, general purpose declarative query functionality that can be applied to in-memory and persisted data. These new language features are:
  • Implicitly typed local variables whose type can to be inferred from the expressions used to initialize them.
  • Extension methods enable additional methods to be added to existing types.
  • Lambda expressions are a new form of anonymous methods that provide improved type inference and conversions to delegate types and expression trees.
  • Expression trees, which permit lambda expressions to be represented as data (expression trees) instead of code (delegates).
  • Object and collection initializers combine creation and initialization into a single step, allowing values to be specified for fields or properties for newly created objects.
  • Anonymous types, which are tuple types automatically inferred and created from object initializers.
  • Query expressions provide a language-integrated syntax for queries similar to relational and hierarchical query languages such as SQL and XQuery. This provides compile time checking of queried types, rather than at runtime. A definite productivity boost.
A great way to find out about the enhancements in C# 3.0, is to download the LINQ preview and to work through the short tutorials, which showcase all of the additions listed above. NOTE: I suggest you run up a VPC image, as LINQ does not yet have a Go Live license available. You can download BLINQ here.

I’ll explore some examples of these new language features in a couple of subsequent posts.

References:
Hands-On Lab: Lab Manual: C# 3.0 Language Enhancements


    

Powered by Blogger