C# Dictionaries
Initialization
Dictionary<key_type, value_type> dic = new Dictionary<key_type, value_type>;
Useful functions
method | action |
---|---|
dic.ContainsKey(key) |
|
dic.Contains(key, value) |
|
dic[key] |
returns value associated with that key or throws KeyNotFoundException |
dic.TryGetValue(key, out value) |
returns true or false, loads value with any data found |
dic.Remove(key) |
Looping
foreach(KeyValuePair<keyType, valueType> item in dic) {
// do something
}