本文介绍了在自己的类中调用构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 如何在构造函数本身的同一个类中调用构造函数? 谢谢。 解决方案 class Foo { public Foo(string s){...} public Foo(int i) :this(i.ToString()){} //喜欢这个 - > ^^^^^^^^^^^^^^^^^^^^ } Mattias - Mattias Sj?gren [MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com 请回复到新闻组。 class Foo 公共Foo(字符串s){...} 公共Foo(int i) :this(i.ToString()){} //像这样 - > ^^^^^^^^^^^^^^^^^^^^ } 我很抱歉赢了''解决我的问题,因为我需要做的是 从同一个类的另一个方法调用构造函数(而不是来自 同一类的另一个构造函数) 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. 解决方案class Foo{public Foo(string s) { ... }public Foo(int i) : this(i.ToString()) {}// like this -> ^^^^^^^^^^^^^^^^^^^^}Mattias--Mattias Sj?gren [MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.comPlease reply only to the newsgroup. 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 tocall a constructor from another method of the same class (not fromanother constructor of the same class) 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) 这篇关于在自己的类中调用构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!