Possible duplicate:Virtual call of the participant in the constructor
Firstly, why is there no error for calling a virtual function inside ctor in C #?Secondly, if allowed, why is Resharper still warning about this?
Already answered:
Virtual call of the participant in the constructor
, - , , , : , .
, :
public class Base { protected virtual void DoSomething() { // do nothing } public Base() { DoSomething(); } } public class Another : Base { private List<string> list; public Another() { list = new List<string>(); } protected override void DoSomething() { // this code will raise NullReferenceException, // since this class' constructor was not run yet, // still, this method was run, since it was called // from the Base constructor list.Add("something"); } }
, , :
, ++, . , ++ [3], , Java #, Factory , .
, ReSharper , , , , , . , :
Source: https://habr.com/ru/post/1755344/More articles:Hexadecimal floating point - numbersRefactoring two methods with almost identical content - c #Heroku installation on Ubuntu Lucid Lynx broken - ruby-on-railsWhy do I have memory leaks using tools on the device, but not on the simulator - debuggingCriticism of my prime_factors () function - pythonРекурсивная программа Python для простого факторизации числа - pythonCall Javascript on a web page with Java - javaProblem with video 5 - htmlWhy svn: executable works for one script and not another? - linuxCapturing groups in regexp variable in Perl - regexAll Articles