例如我写一个这样的字典
Dictionary<int, int> dic = new Dictionary<int, int> { { 1, -1 }, { 2, -1 }, { 3, -1 }, { 4, 2 }, { 5, 2 },
{ 6, 5 }, { 7, 1 }, { 8, 2 }, { 9, 1 }, { 10, 7 }};
现在想遍历,key是节点,value是父节点。-1表示根节点。
想把各根节点的子节点找出来。
Dictionary<int, int> dic = new Dictionary<int, int> { { 1, -1 }, { 2, -1 }, { 3, -1 }, { 4, 2 }, { 5, 2 },
{ 6, 5 }, { 7, 1 }, { 8, 2 }, { 9, 1 }, { 10, 7 }};
现在想遍历,key是节点,value是父节点。-1表示根节点。
想把各根节点的子节点找出来。
.Where(x => x.Value == -1)
.OrderBy(x => x.Key)
.Select(x => x.Key)
.ToList();
Assert.AreEqual(1, q[0]);
Assert.AreEqual(2, q[1]);
Assert.AreEqual(3, q[2]);
.Where(x => x.Value == -1)
select q这一句就OK了