Example of Composite Anonymous Types in C#


This content was proof-read by Grammarly. You can Try Grammary for FREE

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
Newsletter Signup

Subscribe to our weekly newsletter below and never miss the latest product or an exclusive offer.

Newsletter Signup

Subscribe to our weekly newsletter below and never miss the latest product or an exclusive offer.

%d bloggers like this: