- Anonymous type
Anonymous types are a feature of the C# 3.0, Visual Basic .NET 9.0, and Chrome 2.0
programming language that allowsdata type s with named fields to be created implicitly from the code that requires it. This is an important feature for theSQL -likeLINQ feature that will be integrated into C#. Since anonymous types do not have a named typing, they must be stored invariable s declared using thevar
keyword, telling the C# compiler to usetype 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.Example (C#)
Example (Visual Basic .NET)
Example (Oxygene)
var person := new class(FirstName := 'John', LastName := 'Smith');
ee also
*
Extension method
*Lambda expression
*Expression tree References
* [http://spellcoder.com/blogs/bashmohandes/archive/2006/12/08/4027.aspx C# 3.0 Language Enhancements Presentation]
* [http://www.studyvb.com/ Anonymous Types in Visual Basic 2008] - Learn about the new features in Visual Basic 2008.
Wikimedia Foundation. 2010.