private or internal types or private members that are never executed or referenced are dead code:
unnecessary, inoperative code that should be removed. Cleaning out dead code decreases the size of the maintained codebase, making it easier to
understand the program and preventing bugs from being introduced.
public class Foo
{
private void UnusedPrivateMethod() {...} // Noncompliant
private class UnusedClass {...} // Noncompliant
}
public class Foo
{
public Foo()
{
UsedPrivateMethod();
}
private void UsedPrivateMethod()
{
var c = new UsedClass();
}
private class UsedClass {...}
}
This rule doesn’t raise issues on:
Main method void Foo(object, EventArgs) that are declared in partial class System.SerializableAttribute attribute. System.Runtime.CompilerServices.InternalsVisibleToAttribute attribute.