Thursday, December 13, 2012

Anonymous types

C# 3.5 supports anonymous types, through which you can declare simple objects with properties without Class definition

var v = new { Name = "Bob", Age = 20 };
Here a new type will be created with two properties Name and Age.
Name will have type String and Age will have type Integer.
var helps here to declare v using automatic type inferencing.
.Net will create a type and will use it implicitly.

No comments:

Post a Comment