Stats

79 Contributors: 6
2016-10-31
Licensed under: CC-BY-SA

Not affiliated with Stack Overflow
Rip Tutorial: info@zzzprojects.com

Download eBook

Object initializers

Download c# eBook

Syntax

  • SomeClass sc = new SomeClass { Property1 = value1, Property2 = value2, ... };
  • SomeClass sc = new SomeClass(param1, param2, ...) { Property1 = value1, Property2 = value2, ... }

Remarks

The constructor parentheses can only be omitted if the type being instantiated has a default (parameterless) constructor available.

Related Examples