我有一个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]));
}
Run Code Online (Sandbox Code Playgroud)
这有什么奇特的方法吗?我正在使用C#4.0,所以答案可能会利用新的语言功能.