Hi all!
Imagine a System.Collections list (e.g. an ArrayList or a HashTable) containing person objects with surnames.
If you wanted to search this list for all people whose surname starts with a specific string (e.g. "Sm" when wanting to find "Smith", "Smithers", ...), which System.Collections list is the best to use?
Of course I could simply use an ArrayList and the following code:
foreach (Person p in list)
{
if p.Surname.StartsWith("Sm")
// here is a matching object
}
However this is slow, is there a better way using e.g. an ordered list or a hash table?
I'd be very much interested in the fastest way ;-) (insertion time is not much of an issue.)
Thanks a lot,
Anne
Imagine a System.Collections list (e.g. an ArrayList or a HashTable) containing person objects with surnames.
If you wanted to search this list for all people whose surname starts with a specific string (e.g. "Sm" when wanting to find "Smith", "Smithers", ...), which System.Collections list is the best to use?
Of course I could simply use an ArrayList and the following code:
foreach (Person p in list)
{
if p.Surname.StartsWith("Sm")
// here is a matching object
}
However this is slow, is there a better way using e.g. an ordered list or a hash table?
I'd be very much interested in the fastest way ;-) (insertion time is not much of an issue.)
Thanks a lot,
Anne