In an asp.net mvc application, I am trying to perform a selection based on what user selects from product specifications.
Imagine a user selected these parameters as a selection:
manufacturer: [apple, sony, samsung]
ram: [8, 128, 256]
size: [12, 13.5]
based on that, lets say the selection resulted in lists of product Ids.
list1={10,12,18,100}
list2={10,18,20,21,100,102}
list3={1,2,9,10,12,18,100}
the result should be common Ids:
result={10,18,100}
Since there might be more than 3 lists, is there a Linq command for any number of lists?
2
Answers
You can use the
Intersect
method provided by .NET. Here’s the documentation about the usageUse intersect to get similar item from Two Lists.
Output:-
Apple
Banana
Orange