可以使用ConcurrentDictionary的构造函数,接受一个IEnumerable<KeyValuePair<TKey,TValue>>类型的参数,将Dictionary转换为ConcurrentDictionary

示例代码:

Dictionary<string, int> dict = new Dictionary<string, int>();
dict.Add("key1", 1);
dict.Add("key2", 2);

ConcurrentDictionary<string, int> concurrentDict = new ConcurrentDictionary<string, int>(dict);
c# Dictionary 转换成ConcurrentDictionary

原文地址: https://www.cveoy.top/t/topic/eN8G 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录