I have a huge set in memory (e.g. ~ 100K entries) of simple CLR objects of a certain type. This type has the public property int Id {get; set;}. What is the best .NET framework that contains this huge dataset to provide quick access to any element by its identifier? More specifically, this data set is supposed to be used inside a loop to find an item by identifier, so the search should be performed as quickly as possible. The search might look like this:
var entity = entities.First(e => e.Id == id)
IEnumerable-based structures such as collections and lists will go through each data item until a search is found. What are the alternative ways? I believe that there should be a way to do a search for sorted arrays by identifier, like searching for an index in databases.
thank
Test results : FYI: The dictionary is not just fast, it is simply incomparable. My little test showed an increase in performance from about 3000+ ms (calling First () on IEnumerable) to 0 ([index] in the dictionary)!
source
share