sakthi
sakthi

Reputation: 161

convert list<int> to list<long>

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

Upvotes: 16

Views: 23864

Answers (3)

Rex M
Rex M

Reputation: 144172

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

Upvotes: 19

fryguybob
fryguybob

Reputation: 4410

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

Upvotes: -3

SLaks
SLaks

Reputation: 888077

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

Upvotes: 33

Related Questions