Sunday, April 24, 2011

What's new in C# 3.0

C# 3.0 introduces several new features. Few of them are

1. Implicitly types local variable
var a = 10;

2. Extension methods
Built in types can be extended using extension methods.
like ToInt32(string s) can be added to String data type. All the extension methods should be declared as static methods

3. Lambda expression:
More sophisticated anonymous methods.

Anonymous methods requires parameter types should be explicitly stated, where as lambda expressions can infer the parameter types if omitted

4. Object and collection initializers

customer c = new customer { name="custname", id = "1234"};

List ages = new List{1,2,3,4,5}

5. Anonymous Types

var a = new { a="10", b = "100"}

6. Implicitly types arrays
var a = new[] {1,2,3,4};

7. Automatically Implemented properties
public int x {get;set;}

8. Query Expression (using from keyword)


Refer: http://msdn.microsoft.com/en-us/library/bb308966.aspx#csharp3.0overview_topic22

No comments:

Post a Comment