通过LINQ </string>过滤一个List <string>

时间:2009-10-20 02:58:01

标签: c# linq

我有一个主要的颜色列表:

List<string> completeList = new List<string>{"red", "blue", "green", "purple"};

我正在传递产品现有颜色的列表

List<string> actualColors = new List<string>{"blue", "red", "green"};

如何获得完整列表顺序的列表? (红色,蓝色,绿色)

1 个答案:

答案 0 :(得分:16)

var ordered = completeList.Intersect(actualColors);

如果不起作用,请执行此操作

var ordered = actualColors.Intersect(completeList);