If I want to initialize a grouping list, can I do this inline?
Context Update
I already know that I cannot initialize the interface, but is there an implementation already built into dotnet?
I don’t want to create my own implementation, because I am trying to reorganize an existing private method into my own class, which is publicly available, so I need to pass parameters for unit testing.
void MyMethod(IList<IGrouping<int, MyObject>> objGroupings)
Currently, I resorted to initializing the list and then grouping by key:
var fooList = new List<MyObject>
{
new MyObject{ foo = 5 },
new MyObject{ foo = 5 },
new MyObject{ foo = 5 },
new MyObject{ foo = 2 },
new MyObject{ foo = 2 }
};
var fooGrouping = fooList.GroupBy(o => o.foo).ToList();
source
share