C# Language Object initializers

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

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.



Got any C# Language Question?