Can someone verify what I think a hash table does is correct?

Let's say I have a have a massive list with a count of 100,000. Let's also say that not every element is the same type, but every element is derived from the same base class.

If I understand correctly, if I wanted to get a list of every element from of a particular type I would have to iterate through every element in the table, check if it's the type I'm looking for, and then return the list. Something like this:

List<Parent> GetObjectsOfType<T>() { List<T> result; foreach(Parent parent in bigAssList) { if (parent is T) { result.Add(parent); } } return result; } 

That obviously won't do. Especially with a list as large is ours. From what I understand, hash tables keep internal lists that are populated when inserting. That way if you need all objects of type the list is already made and can be returned without having to iterate through every element.

Is this correct? If not, what can allow me to do this?

by Asusralis via /r/csharp

Leave a Reply