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?
Thank you.
你可以使用ConvertAll:
List<short> sList = uList.ConvertAll(x => (short)x);
List<short> sList = uList.Select(i => (short)i).ToList();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.