What you're looking for is a multimap.
You may want to take a look at the answer to this question.
You may also want to look into the C5 Generic Collection library, which is free and has an implementation of a multimap.
If you feel like rolling your own, a simple place to start is a dictionary of lists:
Dictionary<TKey,List<TValue>>
However, you can't add to such a dictionary the normal way. You have to first check if the key already exists, and if so, fetch the value (list) and add to it. Otherwise, you need to create the list and populate it with a value.
If you are so inclined, I would suggest you consider using a set of extension methods to simplify the Add/Remove operations:
public static class MultimapExt
{
public static void Add<TKey,TValue>(
this Dictionary<TKey,List<TValue>> dictionary, TKey key, TValue value )
{
List<TValue> valueList;
if( !dictionary.TryGetValue( key, out valueList )
{
valueList = new List<TValue>();
dictionary.Add( key, valueList );
}
valueList.Add( value );
}
public static void Remove<TKey,TValue>(
this Dictionary<TKey,List<TValue>> dictionary, TKey key, TValue value )
{
List<TValue> valueList;
if( dictionary.TryGetValue( key, out valueList ) )
{
valueList.Remove( value );
if( valueList.Count == 0 )
dictionary.Remove( key );
}
}
}