Created
March 27, 2015 00:29
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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