Tho*_*eld 1 c# linq lambda dictionary
第一个Dictionary就像
Dictionary<String, String> ParentDict = new Dictionary<String, String>();
ParentDict.Add("A_1", "1");
ParentDict.Add("A_2", "2");
ParentDict.Add("B_1", "3");
ParentDict.Add("B_2", "4");
ParentDict.Add("C_1", "5");
Run Code Online (Sandbox Code Playgroud)
我需要将其转换为新的 Dictionary<String, Dictionary<String,String>>
结果将包含
Key Value
Key Value
_________________________________________________
"A" "A_1" "1"
"A_2" "2"
"B" "B_1" "1"
"B_2" "2"
"C" "C_1" "1"
Run Code Online (Sandbox Code Playgroud)
现在我正在使用nested for loop这个.
我怎么能用LNQ或LAMBDA Expression?
var result = ParentDict.GroupBy(p => p.Key[0].ToString())
.ToDictionary(g => g.Key, g => g.ToDictionary(x => x.Key, x => x.Value));
Run Code Online (Sandbox Code Playgroud)