为什么不能在另一个构造体构造访问? [英] Why can't access constructor in body of another constructor?

查看:112
本文介绍了为什么不能在另一个构造体构造访问?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以在另一个构造访问构造像下面,但有没有访问它在构造函数中的身体?



 <$ C $方式C>公共矩形(INT大小):这个(尺寸,大小)
{
Console.WriteLine(方构造方法中调用);
//这个(尺寸,大小);我要像这样访问
}


解决方案

你不能做到这一点。完整的理由是这里,但总结:




在短,达到理想的施工控制流程很容易不加的能力[做调用在任意位置的基础构造],而且也没有令人信服的好处添加功能。没有新的有趣的代表性的功率被添加到语言



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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆