What do you mean by Anonymous Types in Csharp 3.0
| In C# 3.0 we have options to create an instance of a class without writing code for the class beforehand.And code is so simple :-
new {book="dotnet", writer="pervej", ageofwriter=24} In behind C# 3.0 compiler would create a class that looks as follows:class __anonymous {private string _book="dotnet"; private string _writer="pervej";private int _ageofwriter=24; public string book {get { return _book; } set { _book = v |
|
| alue; }}
public string writer {get { return _writer; } set { _writer = value; }} public int ageofwriter {get { return _ageofwriter; } set { _ageofwriter = value; }}} in c# 3.0 we declare the same sequence of names and types , the C# compiler be smart enough to create a single anonymous type for both instances for use they are exchanged because the types are really the same.we have class, but still need something to take an instance of the above class. here the "var" keyword comes in handy it helps to hold a statically typed instance of the above instance of the anonymous type. Here is simple syntax of an anonymous type: var interviewquestion = new {book="dotnet", writer="pervej", ageofwriter=24} | |
