Anonymous type

From Wikipedia, the free encyclopedia

Anonymous types are a feature of the C# 3.0 programming language that allows data types with named fields to be created implicitly from the code that requires it. This is an important feature for the SQL-like LINQ feature that will be integrated into C#. Since anonymous types do not have a named typing, they must be stored in variables declared using the var keyword, telling the C# compiler to use type inference for the variable.

This feature should not be confused with dynamic typing. While anonymous types allow programmers to define fields seemingly "on the fly", they are still static entities. Type checking is done at compile time, and attempting to access a nonexistent field will cause a compiler error. This gives programmers much of the convenience of a dynamic language, with the type safety of a statically typed language.

[edit] Example

var person = new {FirstName = "John", LastName = "Smith"}

[edit] See also

[edit] References