开发者

Filtering one List<string> from another via LINQ

开发者 https://www.devze.com 2022-12-09 12:14 出处:网络
I have a master list of colors: List<string> completeList = new List<string>{\"red\", \"blue\", \"green\", \"purple\"};

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

精彩评论

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