我知道我可以像下面这样在另一个构造函数上访问构造函数,但是有没有办法在构造函数的主体中访问它?
public Rectangle(int size) : this(size, size)
{
Console.WriteLine("Square Constructor Called");
//this(size,size); i want to access like this
}
最佳答案
你不能那样做。完整的理由是 here , 但总而言之:
In short, achieving the desired construction control flow is easy to do without adding the [the ability to call base constructors in arbitrary locations], and there's no compelling benefit to adding the feature. No new interesting representational power is added to the language.
关于c# - 为什么不能在另一个构造函数的主体中访问构造函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3423978/