using System;
using System.Collections.Generic;
using System.Linq;
class Dictionary
{
static void Main()
{
Dictionary<string,Dictionary<string,float>> dict = new Dictionary<string, Dictionary<string, float>>();
String input = Console.ReadLine();
String[] data = input.Split();
string name = "";
float result = 0;
while (data[0] != "end")
{
if (data.Length == 1)
{
name = data[0];
dict.Add(name, new Dictionary<string, float>());
}
else if (data.Length > 1)
{
result = float.Parse(data[1]);
dict[name].Add(data[0], result);
}
data = Console.ReadLine().Split(); // input
}
// var dic2 = from x in dict
// orderby x.Key
// select x;
foreach (var item in dict)
{
Console.WriteLine("Country: {0}", item.Key);
string temp = item.Key;
foreach (var element in dict[temp])
{
Console.WriteLine("City: {0}, population: {1}", element.Key, element.Value);
}
}
}
}
我有一個字典密鑰 - >國家,nested->詞典密鑰 - >城市價值 - >人口,我想
排序的國家和人民內部的「嵌套」字典。我 花了幾個小時尋找正確的答案,但找不到解決我的問題的 。我能夠對信息進行foreach,但找不到排序方式。任何幫助讚賞。 PS:我現在只學習字典。 謝謝。如何排序嵌套字典.net C#?
您能舉一個例子說明您如何期望生成的排序字典的結構? – Dietz