Skip to content

Instantly share code, notes, and snippets.

@JayBazuzi
Created March 27, 2015 00:29
Show Gist options
  • Save JayBazuzi/370c782eeee8de9819f7 to your computer and use it in GitHub Desktop.
Save JayBazuzi/370c782eeee8de9819f7 to your computer and use it in GitHub Desktop.
Example of why FxCop rule CA2214 (Do not call overridable methods in constructors) matters
class C : B
{
string s;
public C()
{
s = "hi";
}
protected override void F()
{
Console.WriteLine(s.Length); // NullReferenceException
}
}
abstract class B
{
protected B()
{
F();
}
protected abstract void F();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment