且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我怎么能转换ConcurrentDictionary到字典?

更新时间:2023-02-16 20:56:48

的ConcurrentDictionary<K,V>$c$c>类实现 的IDictionary&LT; K,V&GT; 一>接口,这应该足以满足大多数要求。但是,如果你真的需要一个具体的Dictionary<K,V>$c$c>...

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);