[英]Class that has a list of itself as a property
I have the following class and wondered if it is allowed?我有以下 class 并想知道是否允许?
public class Node
{
public string Type { get; set; }
public string Id { get; set; }
public string Text { get; set; }
public string ParentNodeId { get; set; }
public List<Node> TargetNodes { get; set; }
}
The code compiles and even works but I am getting stack errors where I shouldn't be getting stack errors and wondered if it is because of my TargetNodes property?代码可以编译,甚至可以工作,但是我在不应该出现堆栈错误的地方遇到堆栈错误,并想知道这是否是因为我的 TargetNodes 属性? Should I create a new class for TargetNodes?
我应该为 TargetNodes 创建一个新的 class 吗?
The problem was unrelated.这个问题是无关的。 I realised the function I was using to populate the nodes was calling itself and creating endless nodes in the list finding new targets and entering a loop.
我意识到我用来填充节点的 function 正在调用自身并在列表中创建无限节点以查找新目标并进入循环。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.