rspec/rules/S2933/csharp/rule.adoc
2021-06-02 20:44:38 +02:00

46 lines
800 B
Plaintext

include::../description.adoc[]
== Noncompliant Code Example
----
public class Person
{
private int _birthYear; // Noncompliant
Person(int birthYear)
{
_birthYear = birthYear;
}
}
----
== Compliant Solution
----
public class Person
{
private readonly int _birthYear;
Person(int birthYear)
{
_birthYear = birthYear;
}
}
----
== Exceptions
* Fields with attributes are ignored.
* Fields of type ``++struct++`` that are not primitive or pointer types are also ignored because of possible unwanted behavior.
== See
* https://ericlippert.com/2008/05/14/mutating-readonly-structs/[Mutating readonly structs]
ifdef::rspecator-view[]
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::rspecator-view[]