C# Associative Arrays
To perform key/value pair style associative "arrays" in C# that you may be familiar with from e.g. PHP you can use the Dictionary class to create a nongeneric collection of key/value pairs.
Sample code with iteration example:
private Dictionary<string, int> OutgoingConnections = new Dictionary<string, int>();
OutgoingConnections.Add("foo") = 1;
OutgoingConnections.Add("bar") = 2;
foreach (KeyValuePair<string, int> c in OutgoingConnections) {
// Do something with c.Key/c.Value.
}
You can declare with
IDictionary
if expected as an argument for something,
but I recommend instantiating the new object itself Dictionary
class.