To get the custom initialization to work like Dictionary you need to support two things. Your type needs to implement IEnumerable
and have an appropriate Add
method. You are initializing an Array
, which doesn't have an Add
method. For example
class PairList : IEnumerable
{
private List> _list = new List>();
public void Add(T1 arg1, T2 arg2)
{
_list.Add(new Pair(arg1, arg2));
}
IEnumerator IEnumerable.GetEnumerator()
{
return _list.GetEnumerator();
}
}
and then you can do
var temp = new PairList
{
{0, "bob"},
{1, "phil"},
{0, "nick"}
};