Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- *
- * http://csharpcodewhisperer.blogspot.com
- *
- * Made using SharpDevelop
- *
- */
- using System;
- using System.Collections.Generic;
- namespace MultiValueDictionary
- {
- public class MultiValueDictionary<K,V>
- {
- Dictionary<K, List<V>> _dictionary = new Dictionary<K, List<V>>();
- public void Add(K key, V value)
- {
- List<V> list;
- if (this._dictionary.TryGetValue(key, out list))
- {
- list.Add(value);
- }
- else
- {
- list = new List<V>();
- list.Add(value);
- this._dictionary[key] = list;
- }
- }
- public int Count
- {
- get { return this._dictionary.Count; }
- }
- public IEnumerable<K> Keys
- {
- get
- {
- return this._dictionary.Keys;
- }
- }
- public IEnumerable<List<V>> Values
- {
- get { return this._dictionary.Values; }
- }
- public List<V> this[K key]
- {
- get
- {
- List<V> list;
- if (!this._dictionary.TryGetValue(key, out list))
- {
- list = new List<V>();
- this._dictionary[key] = list;
- }
- return list;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement