How can I convert anonymous type to strong type in LINQ?

后端 未结 3 1504
南方客
南方客 2021-02-07 05:54

I have an array of ListViewItems ( ListViewItem[] ), where I store a SalesOrderMaster object in each ListViewItem.Tag for later reference.

I ha

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-07 06:31

    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.

提交回复
热议问题