If you don't want to use dynamic you can write your own implementation of ToDictionary method with use of Reflection. Something like this :
public static class Helper
{
public static Dictionary<T1, T2> ToDictionary<T1, T2>(this IEnumerable<object> dict, string key, string value)
{
Dictionary<T1, T2> meowDict = new Dictionary<T1, T2>();
foreach (object item in dict)
meowDict.Add((T1)item.GetType().GetProperty(key).GetValue(item),
(T2)item.GetType().GetProperty(value).GetValue(item));
return meowDict;
}
}
Usage example :
object[] internationalRates = new object[]
{
new { name = "London", value = 1 },
new { name = "New York", value = 2 } ,
};
var dict = internationalRates.ToDictionary<int, string>("value", "name");
foreach (KeyValuePair<int, string> item in dict)
Console.WriteLine(item.Key + " " + item.Value);
Console.ReadLine();
Output :
1 London
2 New York