Search code examples
c#.netcollectionscasting

C# Casting List<ushort> to List<short>


I want to do this:

List<ushort> uList = new List<ushort>() { 1, 2, 3 };
List<short> sList = uList.Cast<short>().ToList();

but I get InvalidCastException "Specified cast is not valid."

How can I cast fast and efficient the above collection?


Solution

  • List<short> sList = uList.Select(i => (short)i).ToList();