Saturday, February 09, 2008

C# 2008 and .NET Framework 3.5 New Features

There are several interesting and new feature with the language for C# 2008 which I will discuss. One of the things that's always been exciting with the .NET Framework and the C# language is that Microsoft continues to evolve the libraries while at the same time improve the core language of C#. C# by the way, is the language I develop in primarily along with PHP and SQL.

Extension Methods

This has to be one of the best features of any language or framework. Extension methods allow you to add methods to an existing class or DLL. What this means is that if you don't have access to the original source code (or type) you can override and add methods to the type class. I thought this was a very interesting feature since this means even with components you purchased, you could add or override the methods as you see fit. VERY COOL!

Implicit Variables

I thought at first this was a strange feature since it was technically going back to the old days of VB where you don't have to define variables explicitly (with their data type) but there are some benefits and are to be used on a case by case basis, such as in the case with LINQ which I will be discussing.

"The LINQ technology set makes use of query expressions that can yield dynamically created result sets based on the format of the query itself. In
these cases, implicit typing is extremely helpful, as we do not need to explicitly define the type that a query may return, which in some cases would be literally impossible to do. " From Apress Pro C# 2008 and the .NET 3.5 Platform

Partial Methods

This is probably the strangest of all the newest features, in .NET 2.0, we have partial classes, which are great because it allows you to split 1 big class into multiple class files. A partial method must return void only, so I don't really see the benefit of it unless you are making one long sequential method, but in that case it's bad design anyway. This feature probably won't be used much.

Object Initializer Syntax

A useful feature since now when I instantiate my objects I can hydrate all the data in them in a few lines, vs. before where I would have to define every single property. Kind of like initializing arrays so a very good feature with less coding.

Anonymous Types

Another interesting feature, when I saw this my first thought is VB object type VARIANT. Aren't variants bad for performance? Again the mention with the use of Anonymous types is with LINQ which I will discuss in another Blog.

Some excerpts from this blog were taken from the Apress book Pro C# 2008 with and the .NET 3.5 Platform

No comments: