Shorter syntax for casting from a List to a List?

I know it’s possible to cast a list of items from one type to another (given that your object has a public static explicit operator method to do the casting) one at a time as follows:

List<Y> ListOfY = new List<Y>();

foreach(X x in ListOfX)
    ListOfY.Add((Y)x);

But is it not possible to cast the entire list at one time? For example,

ListOfY = (List<Y>)ListOfX;

7 Answers
7

Leave a Comment