如何获取密钥和值数组对象

问题描述:

我想要得到数组对象键和值如何获取密钥和值数组对象

enter image description here

+0

为什么使用ArrayLists? – 2017-10-11 05:23:15

+0

支持net 2.0 –

+0

为什么你仍然使用.net 2.0?列表似乎在那里。 – 2017-10-11 05:24:32

你可以这样做:

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

我很确定这是我的错。 – 2017-10-11 05:31:57

您可以用KeyValuePair尝试获得键和数组中的值。

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

} 
+0

你缺少一个空间。 – 2017-10-11 05:29:51

+0

@someone但在OP图像中有数组列表。不可hastable? –

+1

是的,这就是我解决我的评论的原因。 – 2017-10-11 05:31:37

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