我想列出所有類對象。我用'new'標籤創建了一堆對象。在代碼中展示給你更容易。列出所有類對象
static void Main(string[] args)
{
releaseitem trk1 = new releaseitem("ARTIST", "TRACK 01", "2014");
releaseitem trk2 = new releaseitem("ARTIST", "TRACK 02", "2016");
releaseitem trk3 = new releaseitem("ARTIST", "TRACK 03", "2012");
releaseitem trk4 = new releaseitem("ARTIST", "TRACK 04", "2011");
Console.WriteLine("ID\t\t\tArtist\t\tTitle\t\t\tRelease Year");
Console.WriteLine("-----------------------------------------------------------");
trk1.getDetails();
trk2.getDetails();
trk3.getDetails();
trk4.getDetails();
}
你看,在那一刻,我必須單獨獲得每首歌曲的細節,它顯示了這樣的:
不過,我很快就要使它所以用戶可以輸入他們自己的數據,並且我想這樣做以便當用戶鍵入「全部列出」時,它將以屏幕截圖中所示的方式顯示所有曲目。我會告訴你什麼是在releaseitem類,但我不知道我有沒有改變任何東西有:
public class releaseitem
{
private string artist = "";
private string title = "";
private string releaseyear = "";
private string id = "";
public releaseitem(string artist, string title, string releaseyear)
{
this.artist = artist;
this.title = title;
this.releaseyear = releaseyear;
idTracker.nextId += 1;
id = "REL-" + (idTracker.nextId).ToString().PadLeft(4, '0');
}
public void getDetails()
{
Console.WriteLine("{0}\t\t{1}\t\t{2}\t\t{3}", id, artist, title, releaseyear);
}
}
忽略使用「私有」的,我對之差不知道公共和私人,但哈哈。
我不會說超過[C#列表](https://msdn.microsoft.com/en-us/library/6sh2ey19(v = vs.110).aspx),祝你好運! – martijnn2008