C#でKeyValuePairをDictionaryに変換する

KeyValuePair を Dictionary(連想配列)に変換する最もシンプルな方法。 var dictionary = new Dictionary<int, string>(); var kvp = new List<KeyValuePair<int, string>>() { new KeyValuePair<int, string>(1, "hoge"), }; dictionary = kvp.ToDictionary(x => x.Key, x => x.Value); 型が合っていないとビルドエラーになります。