Hi (again with philosophical question),
there is a private static method that does not have an access to instance fields and as far as my readings are concerned those methods provide a little bit of performance improvement.
After you mark the methods as static, the compiler will emit non-virtual call sites to these members. Emitting non-virtual call sites will prevent a check at runtime for each call that ensures that the current object pointer is non-null. This can result in a measurable performance gain for performance-sensitive code. In some cases, the failure to access the current object instance represents a correctness issue.
FxCop
Then why to use normal private method when we can place an instance field in private static method parameters? Isn't that inefficient?
Just to visualize what I mean:
public class A
{
private readonly string _key = "ssss";
public bool IsGoodKey()
{
}
private static bool ValidateKeyStatic(string key)
{
return string.IsNullOrEmpty(key);
}
private bool ValidateKey()
{
return string.IsNullOrEmpty(_key);
}
}
And now there are two ways of implementing IsGoodKey:
public bool IsGoodKey()
{
return ValidateKeyStatic(_key);
}
And
public bool IsGoodKey()
{
return ValidateKey();
}
Why don't always use private static?