CS0029 C#和#x27;无法将类型string[]隐式转换为string';

CS0029 C#和#x27;无法将类型string[]隐式转换为string';,c#,.net,taglib,C#,.net,Taglib,我正在制作一个应用程序来编辑.mp3文件的属性。我不得不说,我对编程和stackoverflow非常陌生,所以我可能做了一些非常明显的错误。请原谅我!这是我正在使用的代码: private void btnApply_Click(object sender, EventArgs e) { var file = TagLib.File.Create(filepath); if (!string.IsNullOrWhiteSpace(txtGenre.Text)) {

我正在制作一个应用程序来编辑.mp3文件的属性。我不得不说,我对编程和stackoverflow非常陌生,所以我可能做了一些非常明显的错误。请原谅我!这是我正在使用的代码:

private void btnApply_Click(object sender, EventArgs e)
{
    var file = TagLib.File.Create(filepath);
    if (!string.IsNullOrWhiteSpace(txtGenre.Text))
    {
        file.Tag.Genres = new string[] {txtGenre.Text};
    }
    if (!string.IsNullOrWhiteSpace(txtArtist.Text))
    {
        file.Tag.Performers = new string[] {txtArtist.Text};
    }
    if (!string.IsNullOrWhiteSpace(txtTitle.Text))
    {
        file.Tag.Title = new string[] {txtTitle.Text};
    }
    file.Tag.Performers = new string[] { txtArtist.Text };
    file.Tag.Title = txtTitle.Text;
    file.Save();

    if (!ReadFile())
    {
        Close();
    }
}
奇怪的是,我只得到了这部分的一个错误:

if (!string.IsNullOrWhiteSpace(txtTitle.Text))
{
    file.Tag.Title = new string[] {txtTitle.Text};
}
红色下划线表示:

new string[] {txtTitle.Text}
我错过了什么?我已经找了很长时间了,但似乎找不到任何解决办法。提前谢谢你!顺便说一句,我也在使用TagLib。

更改此选项:

file.Tag.Title = new string[] {txtTitle.Text};
致:

Title
类型是
string
,而不是字符串数组(不是
string[]
),但您尝试分配数组-因此会出现错误。其他字段的类型为
string[]
(字符串数组),这就是为什么只有
Title
才会出错

此外,您尝试将值赋给
标题
两次:

if (!string.IsNullOrWhiteSpace(txtTitle.Text))
{
    file.Tag.Title = new string[] {txtTitle.Text};    // first time
}
file.Tag.Performers = new string[] { txtArtist.Text };
file.Tag.Title = txtTitle.Text;                       //second time
您只需要指定一次。此外,当您第二次分配时,您可以正确地分配,而不会出错


执行者的情况与执行者相同-您在
if
语句中指定第一次,在最后一次
if

之后指定第二次,然后像这样更改代码并重试

file.Tag.Title = txtTitle.Text;

您了解
string
string[]
之间的区别吗?您正在尝试将
string[]
值放入
string
变量中
file.Tag.Title
是一个
字符串
,您可以尝试使用:
file.Tag.Title=txtTitle.Text@Luctia请不要将问题标题与“已解决:”等状态信息混淆。接受答案就是为了这个目的。谢谢,这删除了下划线,但它不起作用。这样做的目的是在文本框为空时不编辑任何内容。这适用于txt.Genre,但不适用于标题或艺术家。我想我得自己去弄清楚。尽管如此,还是要谢谢你@卢卡蒂亚,见编辑后的答案。删除
file.Save()前面的两行。
。这些行:
file.Tag.Performers=newstring[]{txtart.Text}
file.Tag.Title=txtTitle.Text啊,是的,我刚才试过并测试过了。现在可以了。谢谢你的帮助!
file.Tag.Title = txtTitle.Text;