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

后端 未结 3 1506
南方客
南方客 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:17

    Like Marc Gravell said, you shouldn't access the Tag property from different threads, and the cast is quite cheap, so you have:

    var items = (e.Argument as ListViewItem[]).Select(x=>x.Tag)
             .OfType().ToList();
    

    but then, you want to find distinct items - here you can try using AsParallel:

    var orders = items.AsParallel().Distinct();
    

提交回复
热议问题