I'm making an application to edit the properties of .mp3 files. I have to say I'm pretty new to programming and *, so I might be doing something very obviously wrong. Please forgive me! This is the code I am using:
我正在创建一个应用程序来编辑.mp3文件的属性。我不得不说我对编程和*很新,所以我可能会做一些非常明显错误的事情。请原谅我!这是我正在使用的代码:
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();
}
}
The odd thing to me is that I only get an error for this part:
对我来说奇怪的是我只得到这个部分的错误:
if (!string.IsNullOrWhiteSpace(txtTitle.Text))
{
file.Tag.Title = new string[] {txtTitle.Text};
}
With this being underlined red:
这有红色下划线:
new string[] {txtTitle.Text}
What am I missing here? I've been looking for a very long time but I just can't seem to find any solutions. Thank you in advance! I am also using TagLib, by the way.
我在这里想念的是什么?我一直在寻找很长一段时间,但我似乎无法找到任何解决方案。先谢谢你!顺便说一句,我也在使用TagLib。
2 个解决方案
#1
3
Change this:
改变这个:
file.Tag.Title = new string[] {txtTitle.Text};
to:
至:
file.Tag.Title = txtTitle.Text;
Title
type is string
, not array of strings (not string[]
), but you try to assign array - because of it you get error. Other fields have type string[]
(array of strings), that's why you get error only with Title
.
标题类型是字符串,而不是字符串数组(不是string []),但是您尝试分配数组 - 因为它会导致错误。其他字段的类型为string [](字符串数组),这就是为什么只有Title才会出错。
Also, you try to assign value to Title
2 times:
此外,您尝试将值分配给标题2次:
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
You need to assign only one time. Also, when you assign second time you assign it correctly without error.
您只需要分配一次。此外,当您第二次分配时,您可以正确分配它而不会出错。
The same situation with Performers
- you assign first time inside if
statement and second time after the last if
.
与表演者相同的情况 - 你在if语句中分配第一次,在最后一次if之后第二次分配。
#2
1
Change the code like this and try
像这样更改代码并尝试
file.Tag.Title = txtTitle.Text;
#1
3
Change this:
改变这个:
file.Tag.Title = new string[] {txtTitle.Text};
to:
至:
file.Tag.Title = txtTitle.Text;
Title
type is string
, not array of strings (not string[]
), but you try to assign array - because of it you get error. Other fields have type string[]
(array of strings), that's why you get error only with Title
.
标题类型是字符串,而不是字符串数组(不是string []),但是您尝试分配数组 - 因为它会导致错误。其他字段的类型为string [](字符串数组),这就是为什么只有Title才会出错。
Also, you try to assign value to Title
2 times:
此外,您尝试将值分配给标题2次:
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
You need to assign only one time. Also, when you assign second time you assign it correctly without error.
您只需要分配一次。此外,当您第二次分配时,您可以正确分配它而不会出错。
The same situation with Performers
- you assign first time inside if
statement and second time after the last if
.
与表演者相同的情况 - 你在if语句中分配第一次,在最后一次if之后第二次分配。
#2
1
Change the code like this and try
像这样更改代码并尝试
file.Tag.Title = txtTitle.Text;