我有一个 List<int>
,我想将其转换为 List<double>
。除了遍历 List<int>
并添加到新的 List<double>
中之外,还有其他方法吗:
List<int> lstInt = new List<int>(new int[] {1,2,3});
List<double> lstDouble = new List<double>(lstInt.Count);//Either Count or Length, I don't remember
for (int i = 0; i < lstInt.Count; i++)
{
lstDouble.Add(Convert.ToDouble(lstInt[0]));
}
有没有一种高级的方法可以做到这一点?我正在使用C# 4.0,因此答案可能利用了新的语言特性。
List<T>
)上工作,不能在列表通常情况下(IList<T>
)工作,并且不能在int
和double
之间工作) - Marc Gravell