Difference between Lookup() and Dictionary(Of list())

前端 未结 6 1403
暖寄归人
暖寄归人 2020-11-27 10:56

I\'m trying to wrap my head around which data structures are the most efficient and when / where to use which ones.

Now, it could be that I simply just don\'t unders

6条回答
  •  长情又很酷
    2020-11-27 11:33

    Both a Dictionary> and a Lookup logically can hold data organized in a similar way and both are of the same order of efficiency. The main difference is a Lookup is immutable: it has no Add() methods and no public constructor (and as Jon mentioned you can query a non-existent key without an exception and have the key as part of the grouping).

    As to which do you use, it really depends on how you want to use them. If you are maintaining a map of key to multiple values that is constantly being modified, then a Dictionary> is probably better since it is mutable.

    If, however, you have a sequence of data and just want a read-only view of the data organized by key, then a lookup is very easy to construct and will give you a read-only snapshot.

提交回复
热议问题