Wednesday, 19 August 2015

Anonymous types in

        Anonymous types provide a convenient way to encapsulate a set of read-only properties into a single object without having to explicitly define a type first. You can create anonymous types by using the new operator together with an object initializer .

Example :  var value = new { salary=1000 , message = "Hi"};

        Anonymous types typically are used in the select clause of a query expression to return a subset of the properties from each in the source sequence.

 Example :
var salary = from sal in db.Employee where sal.empid ==1 select new {sal.salary,sal.Message}

1 comment: