Used Namespaces:
using System; using System.Collections.Specialized;
Advantage: 1. We can store duplicate key with different value or same value. 2. Using key we can get all the values of single key. 3. Single Key, but multiple values Disadvantage: 1. We can store and retirive only string values.
Step 1:
Used Namespaces:
Step 2:
public static NameValueCollection GetCollection() { NameValueCollection collection = new NameValueCollection(); collection.Add("Lajapathy", ":INQ"); collection.Add("partiban", "WCF"); collection.Add("partiban", "Silverlight"); collection.Add("Sathiya", "C#"); collection.Add("Sathiya", "dot net"); collection.Add("Sangita", "C#"); return collection; }
Step 3:
public void DisplayOnlyUniqueKeys() { NameValueCollection collection = GetCollection(); // No duplicates returned. foreach (string key in collection.AllKeys) { Response.Write(key + ",");
} }
Step 4:
Step 5:
public void RemoveValue() { NameValueCollection collection = GetCollection(); collection.Remove("Lajapathy"); // No duplicates returned. foreach (string key in collection.AllKeys) { Response.Write(key + ","); } }
Step 6:
public void ClearValue() { NameValueCollection collection = GetCollection(); collection.Clear(); // No duplicates returned. foreach (string key in collection.AllKeys) { Response.Write(key + ","); } }
Step 7:
public void GetDataArray() { NameValueCollection collection = GetCollection(); string[] values = collection.GetValues("partiban"); // No duplicates returned. foreach (string key in values) {
Response.Write(key + ","); } }
Step 8:
public void GeKey() { NameValueCollection collection = GetCollection(); string key = collection.GetKey(1); Response.Write(string.Format("Value :", key)); }
Step 9:
protected void Page_Load(object sender, EventArgs e) { DisplayOnlyUniqueKeys(); DisplayValue(); ClearValue(); GetDataArray(); GeKey(); }