Example of Composite Anonymous Types in C#

Published on June 21, 2015 by abundantcode

Filed under LINQ

Last modified June 21, 2015

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 0 (0 votes)

This article have been viewed 3515 times

The feature of anonymous types can be felt specially when we work with the composite type rather than the simple types. The below example is more like you are defining an inline class without actually having the definition.

Example of Composite Anonymous Types in C#

Below is an example of the anonymous type in C# that demonstrates the composite anonymous type.

using System;
namespace AbundantCodeConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var employee = new { FirstName = "Abundant", Last = "Code.com" };
            Console.WriteLine(employee.);
            Console.ReadLine();
        }
     
    }
}

Note that you will also see the Intellisense support for the anonymous type in Visual Studio wven when the class definition and the properties are not explicitly defined by the developer.

image

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Comment


x

You might be Interested in these Posts

C# and Lambda – Filter elements from object collection with Logical Operators

Here’s a sample code snippet demonstrating how to filter elements from a list of objects using the w...

C# and LINQ – Filter elements from object collection with Logical Operators

Here’s a sample code snippet demonstrating how to filter elements from a list of objects using the w...

C# and Lambda – Filter elements from object collection using Where method

Here’s a sample code snippet demonstrating how to filter elements from a list of objects using the w...