Wednesday 19 August 2015

Anonymous types in C#.net

        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}

2 comments:

  1. wonderful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. This article resolved my all queries. keep it up.


    Dot Net Training in Chennai | Dot Net Training in anna nagar | Dot Net Training in omr | Dot Net Training in porur | Dot Net Training in tambaram | Dot Net Training in velachery

    ReplyDelete