Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# System.Collections.Generic.List`1[测试节点]_C# - Fatal编程技术网

C# System.Collections.Generic.List`1[测试节点]

C# System.Collections.Generic.List`1[测试节点],c#,C#,我有一个名为Node的类 class Node { public int Id { get; set; } public int? ParentId { get; set; } public string Operator { get; set; } public Node Parent { get; set; } public IList<Node> Children { get; set;

我有一个名为Node的类

 class Node
    {
        public int Id { get; set; }
        public int? ParentId { get; set; }
        public string Operator { get; set; }
        public Node Parent { get; set; }
        public IList<Node> Children { get; set; }
        public Node()
        {
            Children = new List<Node>();
        }
        public override string ToString()
        {
            return "Node: " + ParentId + " " + Operator + " " + Id + " " + Children.ToString();
        }
    }
但是我有

[0节点:0~0 System.Collections.Generic.List
1[test.Node]]
[1节点:12+1 System.Collections.Generic.List
1[test.Node]] [2节点:12+2 System.Collections.Generic.List
1[test.Node]]
[3节点:8+3系统.集合.通用.列表
1[test.Node]] [4节点:8+4 System.Collections.Generic.List
1[test.Node]]
[5节点:8+5系统.集合.通用.列表
1[test.Node]] [6节点:8+6 System.Collections.Generic.List
1[test.Node]]
[7节点:8+7 System.Collections.Generic.List
1[test.Node]] [8节点:2~8个System.Collections.Generic.List
1[test.Node]]
[9节点:2~9个System.Collections.Generic.List
1[test.Node]]


替换
Children.ToString()带有:

string.Join(",", Children.Select(x => x.Id));

您正在
IList
上调用
ToString
,因此它会给您类型名称。如果您想查看子节点的ID,可以使用
string。如上图所示加入

将问题分解为一个较小的问题。您的问题是没有显示整个词典。在更高级别的操作中,有一个特定的操作不起作用,还有一堆正在起作用。仅隔离一个不起作用的部分。将代码和问题陈述仅限于不起作用的部分。
string.Join(",", Children.Select(x => x.Id));