I have a collection class that inherits from List<>
. I've set up a function to sort the list by a certain property like so:
public PlaylistCollection SortByName(IEnumerable<Playlist> playlists)
{
return (PlaylistCollection)playlists.OrderBy(p => p.Name);
}
When I try to use the sorted results in my code like this:
artistSource.Playlists = (PlaylistCollection)new List<Playlist>(artistSource.Playlists.SortByName(artistSource.Playlists));
I get the error:
Unable to cast object of type 'System.Linq.OrderedEnumerable`2[...Playlist,System.String]'
to type '...PlaylistCollection'."
This is moderately frustrating considering VS told me that an explicit conversion exists, so I added the above cast.
How do I properly cast from IEnumerable<>
to my collection?