Home >Backend Development >C++ >How Can I Efficiently Cast a List to a List in C#?
Casting from a List
The conversion from a list of items of type X to type Y, where X can be cast to Y, is possible one item at a time:
List<Y> ListOfY = new List<Y>(); foreach(X x in ListOfX) ListOfY.Add((Y)x);
However, a more concise method exists for casting the entire list at once:
List<Y> listOfY = listOfX.Cast<Y>().ToList();
Considerations for Using This Method:
The above is the detailed content of How Can I Efficiently Cast a List to a List in C#?. For more information, please follow other related articles on the PHP Chinese website!