我有一个主要的颜色列表:
List<string> completeList = new List<string>{"red", "blue", "green", "purple"};
我正在传递产品现有颜色的列表
List<string> actualColors = new List<string>{"blue", "red", "green"};
如何获得完整列表顺序的列表? (红色,蓝色,绿色)
答案 0 :(得分:16)
var ordered = completeList.Intersect(actualColors);
如果不起作用,请执行此操作
var ordered = actualColors.Intersect(completeList);