相关疑难解决方法(0)

C#将List <int>转换为List <double>

我有一个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,所以答案可能会利用新的语言功能.

c# generics

25
推荐指数
3
解决办法
2万
查看次数

标签 统计

c# ×1

generics ×1