37 lines
538 B
Plaintext
37 lines
538 B
Plaintext
include::../description.adoc[]
|
|
|
|
== Noncompliant Code Example
|
|
|
|
----
|
|
public class Foo
|
|
{
|
|
public int MagicNumber = 42;
|
|
}
|
|
----
|
|
|
|
== Compliant Solution
|
|
|
|
----
|
|
public class Foo
|
|
{
|
|
public int MagicNumber
|
|
{
|
|
get { return 42; }
|
|
}
|
|
}
|
|
----
|
|
or
|
|
|
|
----
|
|
public class Foo
|
|
{
|
|
private int MagicNumber = 42;
|
|
}
|
|
----
|
|
|
|
== Exceptions
|
|
|
|
``++struct++``s are ignored, as are ``++static++`` and ``++const++`` fields in classes.
|
|
|
|
Further, an issue is only raised when the real accessibility is ``++public++``, taking into account the class accessibility.
|