Fork me on GitHub
TypeName ObjectInitializerAnalyzer
Check Id CC0009
Category Style
Severity Warning


When possible an object initializer should be used to initialize the properties of an object instead of multiple assignments.


Person p;
p = new Person();
p.Name = "Mahmoud";
p.Age = 25;

Code fix

A code fix will be presented to you that will transform the code:

Person p;
p = new Person()
    Name = "Mahmoud",
    Age = 25

Code fix

Related rules

  • CC0008 - Use object initializer (local declaration)

See also