我有一個像一本字典:如何將包含值的字典轉換爲逗號分隔字符串到KeyValuePairs的集合?
Dictionary<string, string> myDict = new Dictionary<string, string>
{
{ "key1", "value1,value2,value3" },
{ "key2", "value4,value5" }
}
我怎麼能轉換成之後自然KeyValuePair
一個List
:
List<KeyValuePair<string, string>> myList = n List<KeyValuePair<string, string>>
{
{ "key1", "value1" },
{ "key1", "value2" },
{ "key1", "value3" },
{ "key2", "value4" },
{ "key2", "value5" }
}
很抱歉的問題主題中可能不清晰。
嘗試這種情況:列表> myList中= myDict。 Keys.Select(x => myDict [x] .Split(new char [] {','})。Select(y => new KeyValuePair (x,y)))。SelectMany(y => Y).ToList(); –
jdweng