: this(foo) syntax in C# constructors?

后端 未结 7 1923
没有蜡笔的小新
没有蜡笔的小新 2020-12-14 19:53

Every now and then, I bump into syntax that I\'ve seen before, but never used. This is one of those times.

Can someone explain the purpose of \":this\" or \":base\"

7条回答
  •  一整个雨季
    2020-12-14 20:13

    You're basically right. this() calls a constructor on the current instance, base() calls the supertype's constructor on current instance. They're generally used to handle constructor overloads so you can add additional options without breaking things out into a separate method.

提交回复
热议问题