2010-07-21 135 views

回答

22

像這樣:

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

這使用C#3.0 lambda表達式;如果你在VS 2005中使用C#2.0中,你需要寫

List<long> longs = ints.ConvertAll<int, long>(
    delegate(int i) { return (long)i; } 
); 
2
var longs = ints.Cast<long>().ToList(); 
+2

我有InvalidCastExpression – Slava 2015-06-18 12:12:50

10
List<int> ints = new List<int>(); 
List<long> longs = ints.Select(i => (long)i).ToList(); 
相關問題