Why are field initializers of a derived class are executed before base classes's initializers

后端 未结 4 1422
逝去的感伤
逝去的感伤 2021-01-05 22:03

constructors are executed in the order from top to bottom I.E. base\'s first followed by derived one. This arangement is based on an important OOP assurance that an object (

4条回答
  •  清歌不尽
    2021-01-05 22:40

    Why are field initializers of a derived class executed before the base class field initializers?

    Good question. I answered your question in these blog posts from 2008:

    https://docs.microsoft.com/en-us/archive/blogs/ericlippert/why-do-initializers-run-in-the-opposite-order-as-constructors-part-one

    https://docs.microsoft.com/en-us/archive/blogs/ericlippert/why-do-initializers-run-in-the-opposite-order-as-constructors-part-two

提交回复
热议问题