我有一个ConcurrentDictionary对象,我想设置一个Dictionary对象。
I have a ConcurrentDictionary object that I would like to set to a Dictionary object.
不允许它们之间的铸造。所以,我怎么办呢?
Casting between them is not allowed. So how do I do it?
的ConcurrentDictionary<K,V>类实现 的IDictionary&LT; K,V&GT;
接口,这应该足以满足大多数要求。但是,如果你真的需要一个具体的Dictionary<K,V>...
var newDictionary = yourConcurrentDictionary.ToDictionary(kvp => kvp.Key,
kvp => kvp.Value);
// or...
// substitute your actual key and value types in place of TKey and TValue
var newDictionary = new Dictionary<TKey, TValue>(yourConcurrentDictionary);