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 am passing a list of existing product colors

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

      

How do I get a list that is in full list order? (Red, blue, green)

+2


source share


1 answer


var ordered = completeList.Intersect(actualColors);

      

If that doesn't work then do this



var ordered = actualColors.Intersect(completeList);

      

+16


source







All Articles