I have 2 DataTables: TableNumber containing mobile numbers and TableCode which contains a mix of all possible mobile codes which is 6 digits long all. i want to create a list to have only numbers which its 6 first digits are from TableCode, so any number which its first digits are not in TableCode will not be considered. i have tried this with foreach, .Contains(), IndexOf() but all are slow because records in numbers are more than 100,000 and it takes too long to loop through all items. and compare with another table. i use 2 nested foreach loop. i'm doing something stupid i think with 2 foreach because that will be 3 billion searches for a 30,000 members from TableCode and it takes me 5 minutes to give me result. my code is like this:
foreach(string codetable in TableCode)
{
foreach(string grouptable in TableNumber)
{
if(grouptable.IndexOf(codetable)!=-1)
{
//work here
}
}
}
here i have added tables' Number rows to a list which contains only numbers so here i am searching lists but similar to this when trying to compare DataTables again it takes too long.