gpt4 book ai didi

C# 无法从字符串 [] 转换为字符串

转载 作者:太空宇宙 更新时间:2023-11-03 17:34:46 24 4
gpt4 key购买 nike

我有这个方法并在行 words.Add(rows); 上得到上面的错误谁能帮忙?谢谢 - 本

private static IEnumerable<string> LoadWords(String filePath)
{

List<String> words = new List<String>();

try
{
foreach (String line in File.ReadAllLines(filePath))
{
string[] rows = line.Split(',');

words.Add(rows);
}

}
catch (Exception e)
{
System.Windows.MessageBox.Show(e.Message);
}

return words;
}

最佳答案

代替

words.Add(rows);

使用这个:

words.AddRange(rows);

rows 是一个包含多个字符串的字符串数组,所以你必须用 AddRange() 添加它们.

关于C# 无法从字符串 [] 转换为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5354984/

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