How do you convert a dictionary to a ConcurrentDictionary?

后端 未结 4 1075
眼角桃花
眼角桃花 2021-01-17 12:04

I have seen how to convert a ConcurrentDictionary to a Dictionary, but I have a dictionary and would like to convert to a ConcurrentDictionary. How do I do that?... better

4条回答
  •  时光取名叫无心
    2021-01-17 12:36

    Or just a have method:

     private ConcurrentDictionary ToConcurrent(Dictionary dic) {
            return new ConcurrentDictionary(dic);
        }
    

    and then do:

    var customers = _customerRepo.Query().Select().ToDictionary(x => x.id, x => x);
    var concurrentDic = ToConcurrent(customers);
    

    Personally, I'm going with the extension method that I just updated...

提交回复
热议问题