The easiest way to look at it is to reduce it to it's basics: A Dictionary class.
Dictionary<string, string> list = new Dictionary<string, string>();
This creates a new Dictionary instance, which takes a string Key and a string Value.
You can assign a new value to a new key:
list["hello"] = "there";
And a new element is created in the Dictionary, which has the Key "hello" and the Value "there".
Like a book based Dictionary, you can access a Value just by specifying the Key:
Console.WriteLine(list["hello"]);
Would print "
there
"
You can create a Dictionary which any .NET class as the key, and any other .NET class as the value, and because it is a Generic class the Value will always be the type you specified. So if you have a Dictionary of TextBoxes:
Dictionary<float, TextBox> list = new Dictionary<float,TextBox>();
TextBox tb = new TextBox();
tb.Text = "Hello, 1.3!";
list[1.3F] = tb;
tb = new TextBox();
tb.Text = "Goodbye, 17.9!";
list[17.9F] = tb;
...
Console.WriteLine(list[1.3F].Text);
...
foreach (TextBox t in list.Values)
{
Console.WriteLine(t.Text);
}
It will sort itself out...
(though I wouldn't really recommend a float Key in practice! :laugh: )
In the case of an HttpCookie, it does the same thing - it uses an internal Dictionary to hold the Key/Value pairs - but it also generates the code to update the cookies on the client machine, or fetch the value from the client via the postback.