0

试图在列表框中打印歌曲刺痛。我尝试将它们添加为项目,但这只是打印 windowsform1.cs。我是否必须转换项目,或者它们是列表框打印字符串和 int 所需的功能。

private string title;
private string album, title, artist, genre;
private int length;

private void List_Click(object sender, EventArgs e)
{
    MDB.listAllSongs(listBox1.Items);

}

public void listAllSongs(IList list)
{
    List<Song> allSongs = new List<Song>();
    foreach (Album album in albums)
    {
        album.listSongs(allSongs);
    }

    foreach (Song song in allSongs)
    {
        list.Add(song.ToString());
    }
}

public void listSongs(List<Song> list)
{
    foreach (Song song in songs)
    {
        list.Add(song);
    }
}
4

1 回答 1

1

您需要在 Song 类中实现 toString() 方法,以返回歌曲的标题:

public string toString()
{
    return title;
}
于 2013-04-07T14:33:26.320 回答