I have a List<int>
and I want to convert it to a List<double>
. Is there any way to do this other than just looping through the List<int>
and adding to a new List<double>
like so:
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]));
}
Is there a fancy way to do this? I'm using C# 4.0, so the answer may take advantage of the new language features.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…