Name value collection in C#
The name value collection is same like the HashTable.
We can set the Object value and the Key to that particuar Object.
But the HashTable dont allow theduplicate keyws.
But the NameValueCollection alloes duplicate Keys. as well as it's provide the fast
way of access to it.
Example HashTable:(It'a raise an error because of the duplicate keys "a"
________________________________________________________________________
Hashtable Ht = new Hashtable();
Ht.Add("a", "Object1");
Ht.Add("b", "Object2");
Ht.Add("a", "Object1 Clone");
Console.WriteLine(Ht["b"]);
Console.WriteLine(Ht["a"]);
Example For NameValueCollection:
________________________________
NameValueCollection col1=new NameValueCollection();
col1.Add("a","Today");
col1.Add("a","Yesterday");
col1.Add("a","Tomorrow");
col1.Add("b","Mango");
Console.WriteLine((col1.GetValues(col1.Keys[0])[0]).ToString());
This collection is based on the NameObjectCollectionBase class.
However, unlike the
NameObjectCollectionBase, this class stores multiple string values under
a single key.
No comments:
Post a Comment