gpt4 book ai didi

c# - 在 C# 中将 List 转换为 List

转载 作者:可可西里 更新时间:2023-11-01 08:30:39 26 4
gpt4 key购买 nike

我想转换一个 List<string>List<int> .

这是我的代码:

void Convert(List<string> stringList)
{
List<int> intList = new List<int>();
for (int i = 0; i < stringList.Count; i++)
{
intList.Add(int.Parse(stringList[i]));
}
)

最佳答案

您可以使用 List<T>.ConvertAll<TOutput>(...) 而不是使用 LINQ

List<int> intList = stringList.ConvertAll(int.Parse);

关于c# - 在 C# 中将 List<string> 转换为 List<int>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19740383/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com