开发者

convert list<int> to list<long>

开发者 https://www.devze.com 2023-01-07 23:19 出处:网络
How to convert List<i开发者_开发知识库nt> to List<long> in C#?Like this: List<long> longs = ints.ConvertAll(i => (long)i);

How to convert List<i开发者_开发知识库nt> to List<long> in C#?


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


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


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

精彩评论

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