tags:

views:

75

answers:

2

I am used to doing this in C++. Is this not allowed in C#?

BasicCtor(int a)
{
   return BasicCtor(a, "defaultStringValue"); 
}

BasicCtor(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

+5  A: 
BasicCtor(int a) : this(a, "defaultStringValue")
{
}

BasicCtor(int a, string b)
{
    //blah blah

}
John Saunders
Both of you, many thanks. I learned something today. ^_^
bobber205
@bobber205: Note that you can also force it to call a base class constructor by saying base(...) instead of this(...).
Eric Lippert
A: 
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

Steven_W