views:

282

answers:

1

i have got any no of records in datatable with id field and other fields.. and i have got a arraylist which have got all id of datatable's records.. now i need to check that the perticular id exist in records or not.. for that i can check in datatable or i can check in arraylist (because arrylist also contain all those ids).. so please tell me which will be more faster in such a situation and how much faster it will be.... . i have used arraylist for searching as (VB.NET)

if( objaarraylist.contains(searchid))
A: 

It is hard to tell since you haven't given any code.

ArrayList can be made fast if you can use ArrayList.Sort (preferably just once) and and then do ArrayList.BinarySearch. ArrayList.Contains is slow as it does a linear search.

Best way to find out is to code up both and do some performance measurements on both and compare.

btw, have you considered storing the ids in a hashtable as opposed to an ArrayList?

Hope that helps. Good luck!

Moron