C# language feature:

  • Anonymous types

applies to

  • class/type declarations

benefit

  • Facilitates encapsulation of a set of read-only properties into a single object without having to explicitly define a type first.

how to use

  • Use new operator together with an object initializer (without specifying class/type identifier/name).

example:

        void Use_of_Anonymous_Type_Example() { 
            var myson = new { Age = 12, Name = "Jeff" }; // note class identifier is absent after new keyword!
        }