私はそれをシリアル化できるようにTreeViewを保持するカスタムデータ構造を構築しています。このビットは無関係で背景ですが、私はここに入れています。.NET List.Findランタイムエラー
私はCustomNodeクラスとツリービューがList<CustomNode>
で開催されようとしているがあります。
private class CustomNode
{
public CustomNode()
{}
public CustomNode (string name)
{
NodeName = name;
}
public string NodeName { get; set; }
public int Level { get; set; }
public int Index { get; set; }
public CustomNode parent;
public List<CustomNode> children;
}
これは私が解決しようとしている関連の問題です。私のコードでの時点で私は私が行う特定のCustomNodeの親を見つけたい:
CustomNode customNode = new CustomNode();
//initialise properties of customNode (below)
.
.
.
CustomNode customNodeParent = new CustomNode();
customNodeParent = listOfCustomNodes.Find(_customNode => (_customNode.Index == node.Index && _customNode.Level == node.Level));
customNode.Index = customNodeParent.children.Count;
最後の行では、オブジェクトのインスタンスに設定されていませんオブジェクト参照をスローします。例外。なぜこれが起こっているのか分かりません。
編集:別の問題があります。私が電話するポイント:
customNode.Index = customNodeParent.children.Count;
customNodeParentはnullです。私は何が起こっているのを見る。ノードが見つかりません。それを修正する必要があります。 CustomNode
のあなたの宣言で
'customNodeParent'はnullか' customNodeParent.children'ですか? –