I have a
List
but I need a
List
Is there a way to cast this in c
ConvertAll seems like a better solution, since it doesn't depend on Linq library and is shorter and more intuitive.
But both of them are rather workarounds, than solutions. Both of them create a new collection with the same data. There should be a support for generic covariance in .net, i.e. upcasting in the generic collections, which would allow you to do that naturally. For example:
List ls = (List)List
From my search so far, my conclusion, is that .Net as of 3.5 doesn't support this feature. Hence we have to end up with workarounds.
These are the discussions on the topic: