rspec/rules/S2156/csharp/rule.adoc

28 lines
657 B
Plaintext
Raw Normal View History

2020-12-23 14:59:06 +01:00
The difference between ``private`` and ``protected`` visibility is that child classes can see and use ``protected`` members, but they cannot see ``private`` ones. Since a ``sealed`` class cannot have children, marking its members ``protected`` is confusingly pointless.
2020-06-30 12:48:07 +02:00
== Noncompliant Code Example
----
public sealed class MySealedClass
{
protected string name = "Fred"; // Noncompliant
protected void SetName(string name) // Noncompliant
{
// ...
}
}
----
== Compliant Solution
----
public sealed class MySealedClass
{
private string name = "Fred";
public void SetName(string name)
{
// ...
}
}
----