以下のようなクラスを実装しました。
public class Person
{
public int d, e, f;
public Person()
{
}
public Person(int a)
{
}
public Person(int a, int b)
{
new Person(40, 6, 8);
}
public Person(int a, int b, int c)
{
d = a; e = b; f = c;
}
}
public class Program
{
static void Main(string[] args)
{
Person P = new Person(100, 200);
Console.WriteLine("{0},{1},{2}", P.d, P.e, P.f);// it prints 0,0,0
}
}
ここで、2 つの引数を使用して Person クラスのインスタンスを作成すると、d、e、f の値を設定できません。これは、3 番目のコンストラクターで Person の新しいオブジェクトがまとめて宣言されているためです。
したがって、前のオブジェクトはこの新しいオブジェクトについて何も知りません。
この新しいオブジェクトを取得して、そこから d、e、f に値を割り当てる方法はありますか?