You are doing it wrong. As I can see, you need fast search by
ItemCode
. If so, don't use
List
.
Assuming the declaration is something like
class Item {
internal int ItemCode { get; set; }
internal string Name { get; set; }
}
store your items in
System.Collections.Generic.Dictionary<ItemCode, Item>
, that is, the dictionary of
Item
s indexed by
ItemCode
, see
http://msdn.microsoft.com/en-us/library/xfhwa508.aspx[
^].
Alternatively, use generic
SortedDictionary
or
SortedList
from the same name space. You want get any functional difference, only different trade-off between memory overhead and speed, pretty good in all cases, with complexity of O(1) (for understanding "Big O Notation", see
http://en.wikipedia.org/wiki/Big_O_notation[
^]).
—SA