What is an anonymous class , in fact, is essentially the same as a common definition class, except that it is done by the compiler of the system, first for example.
General situation
//declare a class that contains more than one pasted field Public classPerson () { Public stringname{Set; ge;} Public intage{Set;Get;} . . . . .}//Instantiation and initializationPerson person=NewPerson ();p Erson. Name="Xi Yang sheep";p Erson. Age="Lazy"; 。 。 。 。
As you can see, when there are so many fields, it's too cumbersome, so c#3.0 provides anonymous classes. Syntax isvar name =new {field Assignment};
where Var is different in C # and in JavaScript, C # is simply inferred, based on the assignment to infer the type,Implicitly-typed var. An implicitly typed local variable is a strongly typed variable (as if you have declared the type), but the type is determined by the compiler.
1) The value of the Var type must be a local variable or a static variable
2) var variable must be initialized before declaring
3) The value of a variable cannot be null (so the compiler cannot determine the type)
4) var variable cannot be a method or method group
5) cannot be used to declare parameter types
The Var type in JavaScript does not make judgments, what types can be, what types of variables (such as string,int,double, etc.) are not strictly limited.
// anonymous class; Declares a class #3.0, which is equivalent to putting class initialization and object declaration together var New {title=" Super Good news ", author=" Sunset Eye ", postdate=" 3013-10-9", msg=" announced tonight "};
C # anonymous Class