42 lines
920 B
Plaintext
42 lines
920 B
Plaintext
![]() |
Unnecessary keywords simply clutter the code and should be removed. Specifically:
|
||
|
* <code>partial</code> on type declarations that are completely defined in one place
|
||
|
* <code>sealed</code> on members of <code>sealed</code> classes
|
||
|
* <code>unsafe</code> method or block inside construct already marked with <code>unsafe</code>, or when there are no <code>unsafe</code> constructs in the block
|
||
|
* <code>checked</code> and <code>unchecked</code> blocks with no integral-type arithmetic operations
|
||
|
|
||
|
== Noncompliant Code Example
|
||
|
|
||
|
----
|
||
|
public partial class MyClass // Noncompliant
|
||
|
{
|
||
|
public virtual void Method()
|
||
|
{
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public sealed class MyOtherClass : MyClass
|
||
|
{
|
||
|
public sealed override void Method() // Noncompliant
|
||
|
{
|
||
|
}
|
||
|
}
|
||
|
----
|
||
|
|
||
|
== Compliant Solution
|
||
|
|
||
|
----
|
||
|
public class MyClass
|
||
|
{
|
||
|
public virtual void Method()
|
||
|
{
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public sealed class MyOtherClass : MyClass
|
||
|
{
|
||
|
public override void Method()
|
||
|
{
|
||
|
}
|
||
|
}
|
||
|
----
|