MultiDictionary implementation C# Because C# .NET does not come with a MultiDictionary, I implemented one based on this StackOverflow answer.

The MultiDictionary should be able to hold multiple values for one key and remove the key, if no value is assigned to the key anymore.

I wanted to implement nearly all methods, which the standard Dictionary provides:

void Add(TKey key, TValue value);
bool Remove(TKey key);
void Clear();
bool ContainsKey(TKey key);
bool TryGetValue(TKey key, out TValue value);


To use the MultiDictionary properly some signatures needed to be changed. This is my implementation:

public class MultiDictionary&lt;TKey, TValue&gt;
{
    private readonly Dictionary&lt;TKey, List&lt;TValue&gt;&gt; _Data = new Dictionary&lt;TKey, List&lt;TValue&gt;&gt;();

    public Dictionary&lt;TKey, List&lt;TValue&gt;&gt;.ValueCollection Values =&gt; _Data.Values;
    public Dictionary&lt;TKey, List&lt;TValue&gt;&gt;.KeyCollection Keys =&gt; _Data.Keys;
    public void Add(TKey key, TValue value) { this[key].Add(value); }
    public bool Remove(TKey key, TValue value) { return this[key].Remove(value); }
    public void Clear() { _Data.Clear(); }
    public bool ContainsKey(TKey key) { return _Data.ContainsKey(key); }
    public bool TryGetValue(TKey key, out List&lt;TValue&gt; value) { return _Data.TryGetValue(key, out value); }

    private struct Entry : IEnumerable&lt;TValue&gt;
    {
        private readonly MultiDictionary&lt;TKey, TValue&gt; _Dictionary;
        private TKey Key { get; }

        internal void Add(TValue value)
        {
            if (!_Dictionary._Data.TryGetValue(Key, out var list))
                list = new List&lt;TValue&gt;();
            list.Add(value);
            _Dictionary._Data[Key] = list;
        }

        internal bool Remove(TValue value)
        {
            if (!_Dictionary._Data.TryGetValue(Key, out var list))
                return false;
            var result = list.Remove(value);
            if (list.Count == 0)
                _Dictionary._Data.Remove(Key);
            return result;
        }

        internal Entry(MultiDictionary&lt;TKey, TValue&gt; dictionary, TKey key)
        {
            _Dictionary = dictionary;
            Key        = key;
        }

        public IEnumerator&lt;TValue&gt; GetEnumerator()
        {
            return !_Dictionary._Data.TryGetValue(Key, out var list) ? Enumerable.Empty&lt;TValue&gt;().GetEnumerator() : list.GetEnumerator();
        }
        IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }
    }

    private Entry this[TKey key] =&gt; new Entry(this, key);
}


I wanted to know, if this implementation is valid (working as I expect) and if you have improvements regarding coding style, safety and so on. 

Thanks in Advance!
couple of points from my side:


If you add same TKey instance to your List it will be added only
once. But if you add other instance of TKey but with the same
'content' the end result of Add method is dictionary with two keys with same content and two
lists. Is that part of requirement?


Example:

public class Foo
{
    public string X;
    public int Y;

    public Foo(string x, int y)
    {
        X = x;
        Y = y;
    }
}

var multiDict = new MultiDict&lt;Foo, string&gt;();

var firstFoo = new Foo("abc", 1);
multiDict.Add(firstFoo, "someValue1");
multiDict.Add(firstFoo, "someValue2");

var secondFoo = new Foo("abc", 1);
multiDict.Add(secondFoo, "someValue3");



Similar problem is for TValue, but it's related with removing elements. Solution for both cases is implementing IEqualityComparer for both TKey and TValue and force class user to inject it via constructor and use [THIS] dictonary constructor. That will guarantee uniqueness for your key. Please keep in mind that you should also use RemoveAll method on list to be sure that all elements that matches predicate are removed. 
You're incosistent with indentations of methods, curly brackets,
whitespaces between methods. Please clean that up.
I don't see the point of Entry struct. You can easily get rid of it
and put all methods in MultiDictionary class itself.
I would consider to change interface to more 'detailed' interface.
What I mean by that? Let's say that Remove returns count of elements
actually removed. Point only to consideration.
I will change implementation of Add method to something different,
because you always (when key exists in dictionary or not) seeking
through dictionary twice: first time is on TryGetValue method and
second while attaching list to key. Attaching list to key is
necessary only when you're creating new one.