开发者

Filtering one List<string> from another via LINQ

I have a master list of colors:

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

I'm passing in a List开发者_JAVA百科 of existing colors of a product

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

How do I get a list back that is in the order of the completeList? (red,blue,green)


var ordered = completeList.Intersect(actualColors);

If that doesn't work, do this

var ordered = actualColors.Intersect(completeList);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜