I want to do this:
List<ushort> uList = new List<ushort>() { 1, 2, 3 };
List<short> sList = uList.Cast<short>().ToList();
bu开发者_JAVA技巧t 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();
精彩评论