Yes. You
can call a constructor from another constructor using this keyword.
[フレーム]
(追記) (追記ここまで)
class sampleClass
{
int member1;
string member2;
public sampleClass(int data) {
member1 = data;
}
public sampleClass(int data, string strValue) : this(data) {
member2 = strValue;
}
public void getData() {
Console.WriteLine(Member1: +member1+ Member2: +member2);
}
}
class testClass {
public static void Main() {
sampleClass obj = new sampleClass(10, Good Day!);
obj.getData();
}
}
Output of this code will be:
Member1:10 Member2: Good Day!
In this example, you created an instance of sampleClass by calling the two argument constructor. In the two argument constructor, you call the one argument constructor in which value for member1 is set. After executing the call, the two argument constructor assigns value to member2.