我正在編寫一個應用程序來編輯.mp3文件的屬性。我不得不說我對編程和stackoverflow很新,所以我可能會做一些非常明顯的錯誤。請原諒我!這是我使用的代碼:CS0029 C#'不能隱式地將字符串[]轉換爲字符串'
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。
你明白'string'和'字符串[]'之間的區別? –
你正試圖把一個'string []'值放入一個'string'變量中。 'file.Tag.Title'是一個'字符串' –
你可以試一下:'file.Tag.Title = txtTitle.Text;' – Hackerman