Skip to content

Latest commit

 

History

History
44 lines (31 loc) · 760 Bytes

File metadata and controls

44 lines (31 loc) · 760 Bytes
layout page
title CC0008
tagline ObjectInitializerAnalyzer

|TypeName|ObjectInitializerAnalyzer | |Check Id | CC0008 | |Category | Style | |Severity | Warning |

Cause

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

Example

{% highlight csharp %} var p = new Person(); p.Name = "Mahmoud"; p.Age = 25; {% endhighlight %}

Code fix

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

{% highlight csharp %} var p = new Person() { Name = "Mahmoud", Age = 25 }; {% endhighlight %}

![Code fix]({{ BASE_PATH }}/assets/images/CC0008/codefix0.png)

Related rules

  • CC0009 - Use object initializer (assignment)

See also

TBD