Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to intersect mutliple list with Lambda Expression?

I have a few list. Their count isn't clear.

For example (for 4 list):

List1   List2    List3     List4 
-----   -----    -----     -----
  1       2        3         4
  2       4        8         3   
  3       8        4         5   
  4       11       6         1    
  5       3        7         7    
  6       9        11        9

I want to find the items that are common. It can do with T-SQL in MSSQL.

The result will be like that:

ResultList : (3, 4)

How is it done with Lambda Expression ?

like image 523
sinanakyazici Avatar asked Nov 23 '25 13:11

sinanakyazici


1 Answers

You can use Enumerable.Intersect

var commonItems = list1.Intersect(list2).Intersect(list3).Intersect(list4);
like image 66
Reed Copsey Avatar answered Nov 25 '25 04:11

Reed Copsey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!