Anonymous type
An anonymous type is a nameless data type that is known only within the current scope and verweisbar.
The XML Structure Definition Language XML Schema stipulates that one can define an unnamed ( anonymous ) complex type content in a named element.
In the C # programming language and VisualBasic.NET make the compiler since. NET Framework 3 provides a way to create an anonymous object with named properties in the current scope.
Anonymous types in XML Schema
In the structure definition XML schema language can be defined as part of the definition of an XML element, an anonymous type. This is often used in definitions of lists, as in the following example.
Anonymous types provide the language compiler provides the ability to create a simple object with properties, without having to define it in a separate file as a class. For this purpose, the variable is declared with ' var'.
Example in C #:
Var person = new { first name = "John", Name = " Count ", size = 40 }; With anonymous types, you can also instantiate predefined classes. The properties of the anonymous object is allocated to the public properties of the newly instantiated class. Suppose there exists the Person class with public properties first name, name and shoe size:
Person my person = new Person () { first name = "John", Name = " Count ", shoe size = 40 }; It is also possible to initialize arrays with the anonymous type syntax:
Person [ ] my people = new Person [] {
new Person { first name = "John", Name = " Count ", size = 40},
new Person { first name = " Anne ", name = " Schneider ", size = 38 }
};
During initialization of Dictionary
Dictionary
Anonymous ( generated ) types. NET Framework are directly inherited from System.Object, can not be inherited and the properties are exclusively generated with get_ accessor, which is you can not define the type before a loop and change the property values within the loop.
If you want to define a function that takes an anonymous type as a parameter, you have to define the function parameter as System.Object and read its properties using reflection.