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?
You could use ConvertAll:
List<short> sList = uList.ConvertAll(x => (short)x);
List<short> sList = uList.Select(i => (short)i).ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With