Anonymous type
Anonymous types are a feature of C# 3.0, Visual Basic .NET 9.0, Oxygene, Scala and Go that allows data types to encapsulate a set of properties into a single object without having to first explicitly define a type.[src] This is an important feature for the SQL-like LINQ feature that is integrated into C# and VB.net.[src] Since anonymous types do not have a named type, they must be stored in variables declared using the var keyword, telling the C# compiler to use type inference for the variable.[src] The properties created are read-only in C#, however, they are read-write in VB.net.[src] This feature should not be confused with dynamic typing.[src] While anonymous types allow programmers to define fields seemingly "on the fly," they are still static entities.[src] Type checking is done at compile time, and attempting to access a nonexistent field will cause a compiler error.[src] This gives programmers much of the convenience of a dynamic language, with the type safety of a statically typed language.[src]
Anonymous types are a feature of C# 3.0, Visual Basic .NET 9.0, Oxygene, Scala and Go that allows data types to encapsulate a set of properties into a single object without having to first explicitly define a type.[src] This is an important feature for the SQL-like LINQ feature that is integrated into C# and VB.net.[src] Since anonymous types do not have a named type, they must be stored in variables declared using the var keyword, telling the C# compiler to use type inference for the variable.[src] The properties created are read-only in C#, however, they are read-write in VB.net.[src] This feature should not be confused with dynamic typing.[src] While anonymous types allow programmers to define fields seemingly "on the fly," they are still static entities.[src] Type checking is done at compile time, and attempting to access a nonexistent field will cause a compiler error.[src] This gives programmers much of the convenience of a dynamic language, with the type safety of a statically typed language.[src] ==Examples== ===C#=== var person = new { firstName = "John", lastName = "Smith" }; Console.WriteLine(person.lastName); Output: ===Go=== var person struct { firstName string; lastName string } person.firstName = "John" person.lastName = "Smith" ===OCaml=== let person = object val firstName = "John" val lastName = "Smith" end;; ===Oxygene=== var person := new class(firstName := 'John', lastName := 'Smith'); ===PHP=== $person = new class { public $firstName = "John"; public $lastName = "Smith"; }; ===Scala=== val person = new { val firstName = "John"; val lastName = "Smith" } ===Visual Basic .NET=== Dim person = New With {.firstName = "John", .lastName = "Smith"} ==See also== Extension method Anonymous function Expression tree == References== == External links== C# 3.0 Language Enhancements Presentation Anonymous Types in Visual Basic 2008 - Learn about the new features in Visual Basic 2008.[src]
17 sentences · 17 cited inline · 0 references stored
References
No reference rows published for this article.
Cite this article
MLA
"Anonymous type." encyclopegia.org, 2026, https://encyclopegia.org/wiki/anonymous-type. Accessed 25 November 2026.
Chicago
"Anonymous type." encyclopegia.org. Accessed November 25, 2026. https://encyclopegia.org/wiki/anonymous-type.
APA
encyclopegia.org. (2026). Anonymous type. Retrieved November 25, 2026, from https://encyclopegia.org/wiki/anonymous-type
Accessed November 25, 2026 · CC BY-SA 4.0 · citation page · JSON