How to call other constructors from a constructor in C #?

I have a constructor like:

public Blah(string a, string b)
{

}

public Blah(string a, string b, string c)
{
  this.a =a;
  this.b =b;
  this.c =c;
}

How can I call the second constructor from the first?

as:

public Blah(string a, string b)
{
   Blah(a,b, "");
}
+3
source share
4 answers
public Blah(string a, string b) : this(a, b, "")
{
}

public Blah(string a, string b, string c)
{
    // etc
}
+9
source
public Blah(string a, string b): this(a, b, String.Empty)
{

}

public Blah(string a, string b, string c)
{
  this.a =a;
  this.b =b;
  this.c =c;
}
+5
source
public Blah(string a, string b) : this(a,b, "default_C_String")
{ 

} 

--- regardless of your desired default value for C ...

+1
source

public Blah (line a, line b): this (a, b, String.Empty) {

}

-2
source

Source: https://habr.com/ru/post/1741294/


All Articles