Anonymous Types

Learn about types without any name.

Overview

C# supports anonymous types in addition to methods.

Anonymous types are like regular classes, but they don’t have user-defined names. We use the var keyword, along with the object initializer, to create an anonymous type:

var person = new { Name = "John", Age = 27 };

Now, the person variable contains a reference to an anonymous object:

Get hands-on with 1200+ tech skills courses.