Search notes:

C# - operator new

Anonymous types

Creating an anonymous type with new:
using System;

class Prg {

   static void Main() {
      var anon = new {num = 42, txt = "Hello world"};

      Console.WriteLine($"num = {anon.num}, txt = {anon.txt}");
   }
}
Github repository about-C-Sharp, path: /language/operators/new/anonymous-type.cs

Structs

Structs (types that inherit from System.ValueType) need not be created with the new operator.

See also

Collection initializer and object initializer.

Index