: this(foo) syntax in C# constructors?

后端 未结 7 1922
没有蜡笔的小新
没有蜡笔的小新 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 right.

    : base(...) calls a constructor of the base class.

    : this(...) calls another constructor of the defining class. Most of the time it works merely as a facade.

提交回复
热议问题