Probably something silly that I'm missing, but so far searching has come up with nothing.
I have implemented List<T> on my class, and when using a MyList.Where() function it wont cast back to a MyList object ?
public class VideoList : List<Video>
{
public VideoList GetVideos(bool onlyShorts)
=> (VideoList)this.Where(x => x.IsShort.Equals(onlyShorts)).ToList();
}
Throws error:
Unable to cast object of type
WhereListIterator1[Video]to typeVideoList.
Tried some different types of casting as was suggested online, but thus far i haven't got passed this error. Also tried this, but same problem. Probably some semantics ? Is there a way to resolve this error without foreach recreating the list after the linq statement ?
produces "List<Video>" which can't be upcasted to type VideoList.
If you still want GetVideos returns VideoList, you need to have and use the appropriate constructor (as a possible solution):