Skip to content

Latest commit

 

History

History
27 lines (20 loc) · 589 Bytes

GCop401.md

File metadata and controls

27 lines (20 loc) · 589 Bytes

GCop 401

"Instead of setting the properties in separate lines, use constructor initializers."

Rule description

Object initializers let you assign values to any accessible fields or properties of an object at creation time without having to invoke a constructor followed by lines of assignment statements.

Example

var myObj = new MyClassName();
myObj.Property1 = "somethings";
myObj.Property2 = 2;
myObj.Property3 = 1.2;

should be 🡻

var myObj = new MyClassName
{
    Property1 = "somethings";
    Property2 = 2;
    Property3 = 1.2;
};