C# System.Collections.Generic.List`1[测试节点]
我有一个名为Node的类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;
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.List1[test.Node]]
[1节点:12+1 System.Collections.Generic.List
1[test.Node]]
[2节点:12+2 System.Collections.Generic.List1[test.Node]]
[3节点:8+3系统.集合.通用.列表
1[test.Node]]
[4节点:8+4 System.Collections.Generic.List1[test.Node]]
[5节点:8+5系统.集合.通用.列表
1[test.Node]]
[6节点:8+6 System.Collections.Generic.List1[test.Node]]
[7节点:8+7 System.Collections.Generic.List
1[test.Node]]
[8节点:2~8个System.Collections.Generic.List1[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));