List1: {"123456", "432978", "321675", …} // containing 100,000 members
List2: {"7674543897", "1234568897", "8899776644",…} // containing 500,000 members
I want to extract all items in List2 that their first 6 digits are from List1 members, so here the string “1234568897” is valid because its first 6 digits are from List1’s first item. What it the fastest way of doing this?
foreach(string id in List1)
{
string result = List2.FirstOrDefault(x => x.Contains(id));
if(result!=null)
{
//some works here
}
}
this works for a group of less than 1000 but when List2 items grows this takes too long