I have a class that extends List:
public class MyObjectList : List<MyObject>
{
...
}
Currently, there is a LINQ statement that groups by a key value:
MyObjectList objects = new MyObjectList(); //initializes and loads list
var objectsByKey = objects.GroupBy(obj => obj.MyKey)
.Select(objs => new {MyKey = objs.Key, MyObjs = objs.ToList()})
.ToList();
In the output, MyObjs is of type List< MyObject>, and it lists the correctly grouped objects.
When I try to cast it as MyObjectList, MyObjs ends up being null.
var objectsByKey = objects.GroupBy(obj => obj.MyKey)
.Select(objs => new {MyKey = objs.Key, MyObjs = objs.ToList() as MyObjectList})
.ToList();
How can I get MyObjs to be of type MyObjectList, with the correclty grouped objects?