how to add keys and value dynamically in namevalue collection

Posted by Oswaldlily under C# on 12/12/2011 | Points: 10 | Views : 1512 | Status : [Member] | Replies : 1
System.Collections.Specialized.NameValueCollection myCollection

= new System.Collections.Specialized.NameValueCollection();



myCollection.Add("Arcane", "http://arcanecode.com");

myCollection.Add("PWOP", "http://dotnetrocks.com");

myCollection.Add("PWOP", "http://dnrtv.com");
return collection;
}
static void Main()
{
NameValueCollection collection = GetCollection();
foreach (string key in collection.AllKeys) // <-- No duplicates returned.
{
Console.WriteLine(key);
}
}


This is the way to add values to collection.
now i need to add string value as key and list value as values like

myCollection.Add(readstring,list[i].aaaa);

which not getting added for me




Responses

Posted by: Hmanjarawala on: 12/13/2011 [Member] Bronze | Points: 25

Up
0
Down
if you want List object as value object then you can do the sam like:

var list = new List<string>() {"aaa", "bbb", "ccc", "ddd" };

mycollection.Add(readstring,list);


Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response