我想转换一个 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/