Example of Composite Anonymous Types in C#

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