我有一个要设置为Dictionary对象的ConcurrentDictionary对象。
不允许在它们之间进行强制转换。那么我该怎么做呢?
发布于 2010-12-02 09:04:06
ConcurrentDictionary
类实现了IDictionary
接口,该接口应该足以满足大多数需求。但是如果你真的需要一个具体的Dictionary
...
var newDictionary = yourConcurrentDictionary.ToDictionary(kvp => kvp.Key,
kvp => kvp.Value,
yourConcurrentDictionary.Comparer);
// or...
// substitute your actual key and value types in place of TKey and TValue
var newDictionary = new Dictionary<TKey, TValue>(yourConcurrentDictionary, yourConcurrentDictionary.Comparer);
发布于 2010-12-02 09:09:57
我想我已经找到了一种方法。
ConcurrentDictionary<int, int> concDict= new ConcurrentDictionary<int, int>( );
Dictionary dict= new Dictionary<int, int>( concDict);
发布于 2010-12-02 09:08:54
ConcurrentDictionary<int, string> cd = new ConcurrentDictionary<int, string>();
Dictionary<int,string> d = cd.ToDictionary(pair => pair.Key, pair => pair.Value);
https://stackoverflow.com/questions/4330702
复制相似问题