gpt4 book ai didi

c# - 'string.Join(string, string[])' 的最佳重载方法匹配有一些无效参数

转载 作者:行者123 更新时间:2023-11-30 20:48:39 25 4
gpt4 key购买 nike

我想提取两个标签之间的文本。 “txtReadfile”包含许多标签。我想提取每次出现的标记中的所有文本。

我使用了以下代码。但是当我运行它时,它给出了错误:

Error # Error1 "The best overloaded method match for 'string.Join(string, string[])' has some invalid arguments"
Error # "Argument '2': cannot convert from 'System.Collections.Generic.List<string>' to 'string[]' "

你能帮我调试一下吗?

List<string> destList = new List<string>();
string me = " <ts>(.*?)<t>";
string text =txtReadfile.Text;
foreach (Match match in Regex.Matches(text, me))
destList.Add(match.Groups[1].Value);
string output= string.Join(" ", destList);
MessageBox.Show(output);

最佳答案

.NET 4 之前,String.Join方法只有将数组作为第二个参数的重载。支持IEnumerable<string>仅在 .NET 4.0 中引入。

// From .NET 2.0:
Join(String, String[])
Join(String, String[], Int32, Int32)
Join(String, Object[])

// From .NET 4.0:
Join(String, IEnumerable<String>)
Join<T>(String, IEnumerable<T>)

因此,如果您的目标是较早的框架,则需要调用 ToArray在您的列表中将其转换为 string[] :

string output= string.Join(" ", destList.ToArray());

关于c# - 'string.Join(string, string[])' 的最佳重载方法匹配有一些无效参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24379077/

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