This is the final post about the new features in C# 3.0. You can read the first two posts here and here. In these posts I have just described the new features of C# 3.0 without going much into details. If time permits I will elaborate on each of these. Extension Methods
Prior to C# 3.0, the only way to update member information of a compiled type, was to recode and recompile the code. But now with extension methods we can allow compiled type to obtain new functionality. This is immensely helpful when you want to add functionality to a third party type where you are not allowed to change the code. When you create an extension method, it actually behave as if it was part of the original type. Lets see an example.
You create an extension method by creating a static class with a static method. As you can see in the ExtensionClass the method Reverse is taking a string parameter with this keyword which indicates the the method is accessible to type of string. We are using the reverse method in the DoSomething method of the Extensions class. As seen we are not creating an object the ExtensionClass , instead we are calling the Reverse method on the string itself.
Language INtegrated Query(LINQ) enables you to write queries against
objects. You can query against any object that implements the
Here the first LINQ statement is using a query syntax and the second is using a method syntax. The method syntax uses a lambda expression with Where and Select extension methods. These two LINQ statements are the same and gives out the same result.