convert list<int> to list<long>

本小妞迷上赌 提交于 2020-02-13 07:15:21

问题


How to convert List<int> to List<long> in C#?


回答1:


Like this:

List<long> longs = ints.ConvertAll(i => (long)i);

This uses C# 3.0 lambda expressions; if you're using C# 2.0 in VS 2005, you'll need to write

List<long> longs = ints.ConvertAll<int, long>(
    delegate(int i) { return (long)i; }
);



回答2:


List<int> ints = new List<int>();
List<long> longs = ints.Select(i => (long)i).ToList();



回答3:


var longs = ints.Cast<long>().ToList();


来源:https://stackoverflow.com/questions/3295957/convert-listint-to-listlong

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!