Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compare to list<String> using linq?

I have 3 list List

ListMaster contains {1,2,3,4,....} ..getting populated from DB
List1 contains {1,3,4}
List2 contains {1,3,95}

how to check Which list items are present in master list using linq

like image 534
Rahul Chowdhury Avatar asked Dec 27 '22 03:12

Rahul Chowdhury


1 Answers

var inMaster = List1.Intersect(ListMaster);

or for both list :

var inMaster = List1.Intersect(List2).Intersect(ListMaster);

check if any item from list1, list2 exist in master

var existInMaster = inMaster.Any();
like image 65
Raphaël Althaus Avatar answered Jan 09 '23 16:01

Raphaël Althaus