我可以在 C# 中从同一类的另一个构造函数调用重载的构造函数吗? [英] Can I call an overloaded constructor from another constructor of the same class in C#?
本文介绍了我可以在 C# 中从同一类的另一个构造函数调用重载的构造函数吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以在 C# 中从同一个类的另一个构造函数调用重载的构造函数吗?
Can I call an overloaded constructor from another constructor of the same class in C#?
推荐答案
不,你不能那样做,你可以在 C# 中从另一个构造函数调用构造函数的唯一地方是紧跟在构造函数之后的:"之后.例如
No, You can't do that, the only place you can call the constructor from another constructor in C# is immediately after ":" after the constructor. for example
class foo
{
public foo(){}
public foo(string s ) { }
public foo (string s1, string s2) : this(s1) {....}
}
这篇关于我可以在 C# 中从同一类的另一个构造函数调用重载的构造函数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文