C# Converting List to List

后端 未结 6 1694
星月不相逢
星月不相逢 2020-12-14 07:07

I have a List and I want to convert it to a List. Is there any way to do this other than just looping through the Li

6条回答
  •  我在风中等你
    2020-12-14 07:45

    You can use LINQ methods:

    List doubles = integers.Select(i => i).ToList();
    

    or:

    List doubles = integers.Select(i => (double)i).ToList();
    

    Also, the list class has a ForEach method:

    List doubles = new List(integers.Count);
    integers.ForEach(i => doubles.Add(i));
    

提交回复
热议问题