An anonymous object is a new mechanism for c#3.0, which uses the new keyword and an initializer for an object to create an anonymous object. As the name implies, this object is an anonymous type object when created, with no specific type. When it comes to anonymous objects, the var keyword we talked about earlier comes in handy. Because you do not know the exact type of the object, you can only declare an object with Var.
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 usingSystem.Linq;6 7 namespaceLinqdemo8 {9 class ProgramTen { One Static voidMain (string[] args) A { - - varStudent =New{userid=001, username="it teenager", age= -, classname="it from getting started to giving up"}; the -Console.WriteLine (student.userid+":"+student.username); - - Console.readkey (); + } - + A } at - -}
Look at the results of the operation:
Our compiler first creates a class for the new object, the class name is determined by the compiler, specifies the appropriate property in the class, and then uses that class to create an object.
Anonymous objects for the LINQ topic