About BiDirection dictionary: Bidirectional 1 to 1 Dictionary in C#
My bi-dictionary is:
internal class BiDirectionContainer<T1, T2>
{
private readonly Dictionary<T1, T2> _forward = new Dictionary<T1, T2>();
private readonly Dictionary<T2, T1> _reverse = new Dictionary<T2, T1>();
internal T2 this[T1 key] => _forward[key];
internal T1 this[T2 key] => _reverse[key];
internal void Add(T1 element1, T2 element2)
{
_forward.Add(element1, element2);
_reverse.Add(element2, element1);
}
}
I want to add elements like this:
BiDirectionContainer<string, int> container = new BiDirectionContainer<string, int>
{
{"111", 1},
{"222", 2},
{"333", 3},
}
But im not sure if it right to use IEnumerable
in BiDirectionContainer
?
What should i return if so? Is there any other way to implement such functionality?