如何在构造函数本身的同一个类中调用构造函数? 谢谢。
解决方案如何在与构造函数本身相同的类中调用构造函数?
class Foo { public Foo(string s){...} public Foo(int i) :this(i.ToString()){} //喜欢这个 - > ^^^^^^^^^^^^^^^^^^^^ } Mattias - Mattias Sj?gren [MVP] mattias @ mvps www.msjogren/dotnet/ | www.dotnetinterop 请回复到新闻组。
Mattias Sj?gren写道: 如何在同一个构建函数中调用class作为构造函数本身?
class Foo 公共Foo(字符串s){...} 公共Foo(int i) :this(i.ToString()){} //像这样 - > ^^^^^^^^^^^^^^^^^^^^ }
我很抱歉赢了''解决我的问题,因为我需要做的是 从同一个类的另一个方法调用构造函数(而不是来自 同一类的另一个构造函数)
如果你的意思是 C c1 = new C(); C c2 = c1 .Clone(); 然后Clone看起来像 public C Clone(){ C结果=新C(); 返回结果; } ottomh - Grace + Peace, Peter N Roth Engineering Objects International engineeringobjects Matrix.NET的主页 " Nicolas" < NI ***** @ serpe>在留言中写道 news:41 ********************** @ nan-newsreader-07.noos ... Mattias Sj?gren写道: 如何在与构造函数本身相同的类中调用构造函数?
class Foo {public Foo(string s){...} public Foo(int i):this(i.ToString() ){} //喜欢这个 - > ^^^^^^^^^^^^^^^^^^^^ }
对不起,我不能解决我的问题,因为我需要做的是从同一个类的另一个方法调用构造函数(而不是从同一个类的另一个构造函数)
Hi, How can one call a constructor in the same class as the constructor itself ? Thanks.
解决方案 How can one call a constructor in the same class as the constructor itself ?class Foo { public Foo(string s) { ... } public Foo(int i) : this(i.ToString()) {} // like this -> ^^^^^^^^^^^^^^^^^^^^ } Mattias -- Mattias Sj?gren [MVP] mattias @ mvps www.msjogren/dotnet/ | www.dotnetinterop Please reply only to the newsgroup.
Mattias Sj?gren wrote:How can one call a constructor in the same class as the constructor itself ?class Foo { public Foo(string s) { ... } public Foo(int i) : this(i.ToString()) {} // like this -> ^^^^^^^^^^^^^^^^^^^^ }
I''m sorry that won''t solve my problem, because what I need to do is to call a constructor from another method of the same class (not from another constructor of the same class)
if you mean like C c1 = new C(); C c2 = c1.Clone(); then Clone will look like public C Clone() { C result = new C(); return result; } ottomh -- Grace + Peace, Peter N Roth Engineering Objects International engineeringobjects Home of Matrix.NET "Nicolas" <ni*****@serpe> wrote in message news:41**********************@nan-newsreader-07.noos... Mattias Sj?gren wrote:How can one call a constructor in the same class as the constructoritself ?class Foo { public Foo(string s) { ... } public Foo(int i) : this(i.ToString()) {} // like this -> ^^^^^^^^^^^^^^^^^^^^ }
I''m sorry that won''t solve my problem, because what I need to do is to call a constructor from another method of the same class (not from another constructor of the same class)
更多推荐
在自己的类中调用构造函数
发布评论