System.Collections.Generic.List`1我有下面这个名为NodeclassNode{publicintId{get;放;公共诠释?ParentId{}publicstringOperator{get;放;}publicNodeParent{get;放;}publicIListChildren{get;放;}publicNode(){Children=newList();}publicoverridestringToString(){return"Node:"+ParentId+""+Operator+""+Id+""+Children.ToString();我想得到每个ParentId[0Node:0~05,4]][1node:12+12,3,5,]][2nodes:12+27,5,3]的所有孩子,]]等varmap=newDictionary();File.WriteAllLines(@"C:Usersmyfile.txt",map.Select(x=>"["+x.Key+""+x.Value+"]").ToArray());但是我得到[0Node:0~0System.Collections.Generic.List1[test.Node]][1Node:12+1System.Collections.Generic.List1[test.Node]][2Node:12+2System1[test.Node]][3节点:8+3System.Collections.Generic.List1[test.Node]][4节点:8+4System.Collections.Generic.List1[test.Node]][5节点:8+5System.Collections.Generic.List1[test.Node]][6Node:8+6System.Collections.Generic.List1[test.Node]][7Node:8+7System.Collections.Generic.List1[test.Node]][8节点:2~8System.Collections.Generic.List1[test.Node]][9节点:2~9System.Collections.Generic.ListGeneric.List1[test.Node]]替换儿童.ToString();有:string.Join(",",Children.Select(x=>x.Id));您在IList上调用ToString,因此如果您想查看子项,它会为您提供类型名称对于id,您可以使用string.Join,如上所示。以上就是C#学习教程:System.Collections.Generic.List`1分享的全部内容。如果对你有用,需要进一步了解C#学习教程,希望大家多多关注。本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处:
