Methods and properties that don’t access instance data should be marked as static for the following reasons:
Methods with the following names are excluded because they can’t be made static:
public class Utilities
{
public int MagicNum // Noncompliant - only returns a constant value
{
get
{
return 42;
}
}
private static string magicWord = "please";
public string MagicWord // Noncompliant - only accesses a static field
{
get
{
return magicWord;
}
set
{
magicWord = value;
}
}
public int Sum(int a, int b) // Noncompliant - doesn't access instance data, only the method parameters
{
return a + b;
}
}
public class Utilities
{
public static int MagicNum
{
get
{
return 42;
}
}
private static string magicWord = "please";
public static string MagicWord
{
get
{
return magicWord;
}
set
{
magicWord = value;
}
}
public static int Sum(int a, int b)
{
return a + b;
}
}