How to convert List<int>
to List<long>
in C#?
views:
128answers:
3
+10
A:
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; }
);
SLaks
2010-07-21 02:54:26
+3
A:
List<int> ints = new List<int>();
List<long> longs = ints.Select(i => (long)i).ToList();
Rex M
2010-07-21 03:21:46