Create an Instance of a Nonexistent Class

The .NET languages enable you to create an object that does not have a class representation at design time. Instead, an unnamed (anonymous) class is created for you by the compiler. This feature is called anonymous types. Anonymous types provide crucial support for LINQ queries. With them, columns of data returned from a query can be represented as objects (more on this later). Anonymous types are compiled into class objects with read-only properties.

Let’s look at an example of how you would create an anonymous type. Suppose you want to create an object that had both a Name and a PhoneNumber property. However, you do not have such a class definition in your code. You could create an anonymous type declaration ...

Get Microsoft® Visual Studio® 2010 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.