开发者

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();

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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜