Anonymous type

Anonymous type

Anonymous types are a feature of the C# 3.0, Visual Basic .NET 9.0, and Chrome 2.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.

Example (C#)

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

Example (Visual Basic .NET)

Dim person = New With {.FirstName = "John", .LastName = "Smith"}

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.

Игры ⚽ Поможем сделать НИР

Look at other dictionaries:

  • Anonymous (album) — Infobox Album | Name = Anonymous Type = studio Artist = Tomahawk |center|250px Released = June 19, 2007 Recorded = Nashville (guitars, drums) Vulcan Studios, San Francisco (vocals) 2006 [http://www.ipecac.com/bio.php?id=9 Tomahawk official bio ]… …   Wikipedia

  • Anonymous matching — is a matchmaking method facilitated by computer databases, in which each user confidentially selects people they are interested in dating and the computer identifies and reports matches to pairs of users who share a mutual attraction. The purpose …   Wikipedia

  • Anonymous function — In computing, an anonymous function is a function (or a subroutine) defined, and possibly called, without being bound to a name. In lambda calculus, all functions are anonymous. The Y combinator can be utilised in these circumstances to provide… …   Wikipedia

  • Anonymous remailer — An anonymous remailer is a server computer which receives messages with embedded instructions on where to send them next, and which forwards them without revealing where they originally came from. There are Cypherpunk anonymous remailers,… …   Wikipedia

  • Anonymous P2P — An anonymous P2P computer network is a particular type of peer to peer network in which the users are anonymous or pseudonymous by default. The primary difference between regular and anonymous networks is in the routing method of their respective …   Wikipedia

  • Anonymous (Bobby Valentino song) — Infobox Single Name = Anonymous Artist = Bobby Valentino featuring Timbaland from Album =Special Occasion Released = April 2007 Format = [ Recorded = ] Genre = R B, Hip hop Length = 4:02 (radio edit) 4:44 (album version) Label = DTP/Def Jam… …   Wikipedia

  • Anonymous (group) — Anonymous A flag conveying symbolism associated with Anonymous. The imagery of the suit without a head represents leaderless orga …   Wikipedia

  • Anonymous (communauté) — Pour les articles homonymes, voir Anonymous. Anonymous Région Globale Devise : We are Anonymous. We are Legion. We do not forg …   Wikipédia en Français

  • Anonymous Bodies in an Empty Room — Infobox Album | Name = Anonymous Bodies in an Empty Room Type = Live album Artist = Swans Released = 1990 Recorded = Genre = Experimental rock, Post punk, Progressive Folk Length = Label = Producer = Michael Gira Reviews = Last album = The… …   Wikipedia

  • Alcoholics Anonymous — AA meeting sign Alcoholics Anonymous (AA) is an international mutual aid movement which says its primary purpose is to stay sober and help other alcoholics achieve sobriety. Now claiming more than 2 million members, AA was founded in 1935 by Bill …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”