2023-05-03 11:06:20 +02:00
== Why is this an issue?
2020-06-30 16:59:06 +02:00
Because the use of initializers to set properties and values makes for clearer, more communicative code, it should be preferred for initializing objects and collections.
2023-05-03 11:06:20 +02:00
=== Noncompliant code example
2020-06-30 16:59:06 +02:00
2022-02-04 17:28:24 +01:00
[source,text]
2020-06-30 16:59:06 +02:00
----
var p = new Person();
p.Age = 5; // Noncompliant
p.Name = "John"; // Noncompliant
var l = new List<int>();
l.Add(5); // Noncompliant
l.Add(10); // Noncompliant
----
2023-05-03 11:06:20 +02:00
=== Compliant solution
2020-06-30 16:59:06 +02:00
2022-02-04 17:28:24 +01:00
[source,text]
2020-06-30 16:59:06 +02:00
----
var p = new Person
{
Age = 5,
Name = "John"
};
var l = new List<int> {5, 10};
----