私は以下のクラスを持っており、親クラス内に子と子の子を持つ必要があります。 どうすればいいですか?親クラスと同じプロパティを持つクラス内のプロパティ
public class Person {
public string Name { get; set; }
public int Age { get; set; }
// this person can have one or more children with Name & age properties
//this person's children can have one or more children with Name & age properties
}
それ自体を参照することができ、あなたに
'publicリスト子{get; }は新しいリスト(); 'より一般的に、これは一種の** [再帰的データ型](https://en.wikipedia.org/wiki/Recursive_data_type)** –
' publicリスト子{get;セット;} '? –
GSerg
一部のモニターはあなたの質問に答えさせません。各Childは1つのParentしか持たないので、Childrenのリストを作成しないでください。それぞれの人は、親のリストを持っている必要があります...リスト親。 –