I am used to doing this in C++. Is this not allowed in C#?
BasicCtor(int a)
{
return BasicCtor(a, "defaultStringValue");
}
Bas开发者_高级运维icCtor(int a, string b)
{
//blah blah
}
In C# I can neither return a calling of the constructor or call it w/o a return. Does C# allow what I want to do? :P
BasicCtor(int a) : this(a, "defaultStringValue")
{
}
BasicCtor(int a, string b)
{
//blah blah
}
Have you tried the following:
class MyClass {
MyClass(int a) : this(a, "defaultStringValue")
{
// Any additional constructur code (optional)
}
MyClass(int a, string b)
{
//Original constructor
}
}
--
Note: This assumes C# 3.5 (In c#4. you may be able to omit the other constructor and use default parameters
精彩评论