根据索引获取字典的Key或者value

public string get_Key(Dictionary<string, List<string>> dict, int index)
{
    string k = default(string);
    int sum = 0;
    foreach (string key in dict.Keys)
    {
        sum++;
        if (sum == (index + 1))
            return key;
    }

    return k;
}
public List<string> get_Value(Dictionary<string, List<string>> dict, int index)
{
    List<string> v = default(List<string>);
    int sum = 0;
    foreach (List<string> value in dict.Values)
    {
        sum++;
        if (sum == (index + 1))
            return value;
    }
    return v;
}

你可能感兴趣的:(C#,c#)