Dictionary or KeyedCollection?

后端 未结 6 752
无人及你
无人及你 2020-12-10 00:26

I have a class (SomeClass) which contains a property Name of string type. And I need to store an array of that class and find its item

6条回答
  •  天涯浪人
    2020-12-10 01:00

    None of the previous comments address the most important difference between the two: KeyedCollection keeps your items in the order in which they are added (the first item added is at index 0 and the last added is at the last index). Dictionary does not (or at least it is never guaranteed to do so).

    This extra benefit of KeyedCollection does have a small performance cost. Under the covers, you pay the cost of maintaining both a Dictionary and a List.

提交回复
热议问题