开发者

Convert IDictionary to Dictionary

开发者 https://www.devze.com 2023-03-14 13:22 出处:网络
I have to convert System.Collections.Generic.IDictionary<string, decimal> to System.Collections.Generic.Dictionary<string, decimal>, and i can\'t. I tried the ToDictionar开发者_运维知识库y

I have to convert System.Collections.Generic.IDictionary<string, decimal> to System.Collections.Generic.Dictionary<string, decimal>, and i can't. I tried the ToDictionar开发者_运维知识库y method and can't specify right arguments.

I've tried the following:

// my dictionary is PlannedSurfaces (of type IDictionary<string, decimal>)
blabla.ToDictionary<string, decimal>(localConstruction.PlannedSurfaces) 


var newDict = new Dictionary<string, decimal>(oldDictionary)


or in linq

var castedDico = dictionary.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);


var newDictionary = (IDictionary<string, boolean>)ex.Data;

IDictionary can be casted as a Dictionary.

Note that if dictionary is empty/null, it will throw exception.

0

精彩评论

暂无评论...
验证码 换一张
取 消