When should I use ConcurrentDictionary and Dictionary?

前端 未结 4 991
余生分开走
余生分开走 2021-02-01 01:05

I\'m always confused on which one of these to pick. As I see it I use Dictionary over List if I want two data types as a Key and Val

4条回答
  •  不思量自难忘°
    2021-02-01 01:31

    The biggest reason to use ConcurrentDictionary over the normal Dictionary is thread safety. If your application will get multiple threads using the same dictionary at the same time, you need the thread-safe ConcurrentDictionary, this is particularly true when these threads are writing to or building the dictionary.

提交回复
热议问题