【发布时间】:2011-07-06 17:32:49
【问题描述】:
var listOne = new string[] { "dog", "cat", "car", "apple"};
var listTwo = new string[] { "car", "apple"};
我需要按 listTwo 中的项目顺序(如果存在)对 listOne 进行排序。所以新列表将按此顺序排列; “汽车”、“苹果”、“狗”、“猫”
我想在 LINQ 中执行此操作并尝试过此操作;
var newList = from l1 in listOne
join l2 in listTwo on l1 equals l2 in temp
from nl temp.DefaultIfEmpty()
select nl;
但它返回 null 很明显我的 Linq-Fu 很弱。任何建议表示赞赏。
【问题讨论】:
-
listOne中是否可以存在重复项?如果是这样,它们应该被保留吗?