Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert IDictionary to Dictionary

I have to convert System.Collections.Generic.IDictionary<string, decimal> to System.Collections.Generic.Dictionary<string, decimal>, and i can't. I tried the ToDictionary 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) 
like image 904
croisharp Avatar asked Jun 21 '11 07:06

croisharp


2 Answers

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

like image 58
Ray Avatar answered Sep 19 '22 14:09

Ray


or in linq

var castedDico = dictionary.ToDictionary(kvp => kvp.Key, kvp => kvp.Value); 
like image 36
Tomasz Jaskuλa Avatar answered Sep 19 '22 14:09

Tomasz Jaskuλa