In this article you will learn about Anonymous Types in LINQ.
Anonymous types can be used to initialize simple types like integers and strings.
Rules: The following are some basic rules to use LINQ Anonymous Types.
They must always have an initial assignment.
They can be used with simple or complex types, but composite anonymous types require a member declaration.
Example
In the preceding topic is the member declaration.
Now, let's explore some categories or types of anonymous types.
With the keyword var and giving the value of the variable in the right side of the assignment operator (=), anyone can declare a Simple anonymous type.
The anonymous type is assigned to the name on the left side of the assignment operator and the type emitted by the compiler to the Microsoft Intermediate Language (MSIL) is determined by the right side of the operator.
The preceding line is identical in the MSIL if defined as in the following:
Anyone can use an Anonymous Type to initialize an array too but with the rigid rule that the new keyword must be used.
Let's define it.
Now, let's have a look how to define a Composite Anonymous Type. It's just called a class without the “typed” class definition.
In the preceding, "fullname" contains both first and last name. Go through the following.
Note:
Pro WPF: Windows Presentation Foundation in .NET 3.0