亲爱的朋友们在得到运行的组合,这是像我以前How to get moving combination from two List<String> in C#?C#:如何从两个List <String>基于主列表
我有一个masterlist和两个的childList类似问题下面
List<String> MasterList = new List<string> { "A", "B", "C", "D", "E" };
List<String> ListOne = new List<string> { "A", "B", "C" };
List<String> ListTwo = new List<String> { "B", "D" };
我只需要从该上面的列表中我使用像(前一个问题的回答(感谢丹尼·陈))获得运行中的组合
List<String> Result = new List<string>();
Result = ListOne.SelectMany((a, indexA) => ListTwo
.Where((b, indexB) => ListTwo
.Contains(a) ? !b.Equals(a) && indexB > indexA :
!b.Equals(a)).Select(b => string.Format("{0}-{1}", a, b))).ToList();
这样的结果列表将包含
"A-B"
"A-D"
"B-D"
"C-B"
"C-D"
现在我的问题是排序问题
在上述结果的第四个条目是C-B
但它应该是B-C
。因为在MasterList
的C
之后是B
。
如何在我现有的linq
中做到这一点。
请帮我做到这一点。
我不明白为什么MasterList的。而且,输出不应该是:“A-B,A-D,B-D,C-D”? – 2010-12-20 17:59:52
@ AS-CII:Friend,在ResultList中,这个项目应该是'MasterList'顺序。即它应该以主列表顺序开始 – 2010-12-20 18:03:49
上述代码不会产生“B-D”。 – 2010-12-20 19:13:14