Anonymous Types
Last updated
Was this helpful?
Last updated
Was this helpful?
Anonymous types provide a convenient way to encapsulate a set of read-only properties into a single object without having to explicitly define a type first. The type name is generated by the compiler and is not available at the source code level. The type of each property is inferred by the compiler.
You create anonymous types by using the operator together with an object initializer. For more information about object initializers, see .
The following example shows an anonymous type that is initialized with two properties named Amount
and Message
.C#Copy
Anonymous types typically are used in the clause of a query expression to return a subset of the properties from each object in the source sequence. For more information about queries, see .