I have an array of ListViewItems ( ListViewItem[]
), where I store a SalesOrderMaster
object in each ListViewItem.Tag for later reference.
I ha
The part in that code that is expensive is calling the Contains
method on the list. As it's an O(n) operation it gets slower the more objects you add to the list.
Just use a HashSet
for the objects instead of a List
. The Contains
method of the HashSet
is an O(1) operation, so your loop will be an O(n) operation instead of an O(n*n) operation.