Why the base class constructor is not called first

When using simple syntax to initialize fields of derived classes by directly assigning values ​​to them, the compiler emits IL code that first initializes the fields of the derived class and then calls base.ctor. Why does it not call the base.ctor field and initialize the fields of the derived class. What if I had fields that depend on the fields of the base class?

I would like to post a sample code here, but I am posting this question from my mobile phone.

+3
source share
2 answers

I think this is because it needs to handle the case where the virtual method or intializer is called inside the constructor.

+3
source

.

http://blogs.msdn.com/b/ericlippert/archive/2008/02/15/why-do-initializers-run-in-the-opposite-order-as-constructors-part-one.aspx

. , .

Calling methods on derived types from constructors is dirty pool, but it is not illegal. 

- , .

+2

All Articles