C# 3 has lots of advanced features and enhancements like
- Implicitly typed variables and arrays
- Lambda Expressions, Abstractions and Extension methods
- Object initializers and anonymous types
- LINQ
Implicitly typed variables and arrays
C# is statically typed, now in C# 3 you can now declare a variable without specifying its type. A type inference algorithm in the compiler analyses your program and works out the type for the variable.
Extension Methods
Lambda Expressions, Abstractions and Extension methods
- Extension methods are associated with a class (either a specific one or they are generic and can work for any class). What makes them different from normal instance methods is that they are not defined within the class itself. Instead, they are defined in some other static class.
- A lambda expression simply defines an anonymous function. A function is something that takes one or more parameters (just as a method does) and uses them in computing some value. That value becomes the return value for the function. In C# 3, the "=>" syntax is used to write a lambda expression. You place the parameters to the left of the arrow and the expression to compute to the right.
Object initializers and anonymous types
- In C# code an object is instantiated using the "new" keyword and then having its fields and/or properties set. Until C# 3.0, this could only be done by instantiating the object, storing it in a variable and then doing assignments to the various properties. In C# 3.0, object initializers make this possible within a single expression.
- The anonymous methods are introduced in C# 2.0. The analogy with anonymous classes is that we are required to instantiate them right away. Therefore, the construct for creating an anonymous class also instantiates that class. In C# 3.0, anonymous classes are greatly limited compared to standard classes. They can only inherit from object and their only members are private fields each with a matching read/write property.
LINQ
Linq is short for Language Integrated Query. Linq brings declarative programming features into imperative languages. It is not language specific, and has been implemented in the Orcas version of VB.Net amongst other languages. In this series we are focusing on C# 3.0, but the principles will carry over to other languages.
References:
http://www.programmersheaven.com/2/CSharp3-1
http://www.programmersheaven.com/2/CSharp3-2
No comments:
Post a Comment