Anonymous Types (C# Programming Guide)
Anonymous types provide a convenient way to encapsulate a set of read-only properties into a single object without having to first explicitly define a type. The type name is generated by the compiler and is not available at the source code level. The type of the properties is inferred by the compiler. The following example shows an anonymous type being initialized with two properties called Amount and Message.
var v = new { Amount = 108, Message = "Hello" };
Anonymous types are typically used in the select clause of a query expression to return a subset of the properties from each object in the source sequenceAnonymous types are created by using the new operator with an object initializer.
Anonymous types are class types that consist of one or more public read-only properties. No other kinds of class members such as methods or events are allowed. An anonymous type cannot be cast to any interface or type except for object.
Anonymous Types
Friday, October 23, 2009
Posted by Chirag at Friday, October 23, 2009
Labels: Anonymous Types, Reference guide c#
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment