C# Iterate through NameValueCollection

后端 未结 7 1790
慢半拍i
慢半拍i 2020-12-13 01:43

I have a NameValueCollection, and want to iterate through the values. Currently, I’m doing this, but it seems like there should be a neater way to do it:

相关标签:
7条回答
  • 2020-12-13 02:17
    var enu = myNameValueCollection.GetEnumerator();
    while (enu.MoveNext())
    {
        string key = (string)enu.Current;
        string value = myNameValueCollection[key];
    }
    

    OR when keys nullable:

    for (int i = 0; i < myNameValueCollection.Count; i++)
    {
        string key = myNameValueCollection.GetKey(i);
        string value = myNameValueCollection.Get(i);
    }
    
    0 讨论(0)
提交回复
热议问题