如何获取数组对象中的键和值

时间:2017-10-11 05:22:25

标签: c#

我想从Array Object获取键和值

enter image description here

3 个答案:

答案 0 :(得分:0)

你可以这样做:

foreach(KeyValuePair<string, string> kv in st[u])
{ 
   string key = kv.Key;
   string val = kv.Value;
   //Business logic here
}

答案 1 :(得分:0)

您可以尝试使用KeyValuePair从数组中获取密钥和值。

foreach(KeyValuePair<string, string> kvp in m)
{
 Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value);

}

答案 2 :(得分:0)

    Hashtable hashtable = new Hashtable();
    hashtable[1] = "One";
    hashtable[2] = "Two";
    hashtable[13] = "Thirteen";

    foreach (DictionaryEntry entry in hashtable)
    {
        Console.WriteLine("{0}, {1}", entry.Key, entry.Value);
    }
You can use hashtable like this