为什么不能访问另一个构造函数体中的构造函数? [英] Why can't access constructor in body of another constructor?
本文介绍了为什么不能访问另一个构造函数体中的构造函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道我可以访问另一个构造函数上的构造函数,如下所示,但是有一种方法来访问它的构造函数体。
I know that i can access constructor on another constructor like below but is there a way to access it in body of constructor ?
public Rectangle(int size) : this(size, size)
{
Console.WriteLine("Square Constructor Called");
//this(size,size); i want to access like this
}
推荐答案
你不能这样做。完整的理由是这里是,但总结:
You can't do that. The full justification is here, but in summary:
总之,实现所需的结构控制流程是很容易做到的,在任意位置调用基础构造函数的能力],并且添加功能没有引人注目的好处。没有新的有趣的代表力被添加到语言。
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.
这篇关于为什么不能访问另一个构造函数体中的构造函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文