printing instance data using static properties

I've written some list of classes, here's the code I used to initialize class

  public class Album
   {
       static public int IDNumber { get; set; }
       static public string AlbumName { get; set; }
       static public string Artist { get; set; }
       static public int ReleaseDate { get; set; }
       static public int TrackAmount { get; set; }
       static public string Location { get; set; }
       static public int Rating { get; set; }

       public Album(int _id, string _name, string _artist, int _releasedate, int _trackamount, string _location, int _rating)
       {
           IDNumber = _id;
           AlbumName = _name;
           Artist = _artist;
           ReleaseDate = _releasedate;
           TrackAmount = _trackamount;
           Location = _location;
           Rating = _rating;
       }
   }

I add everything from console like that:

   static private List<Album> AlbumsList = new List<Album>();
   public void addnew()
   { 
       //getting from console to separate variables with names below in .add method
       AlbumsList.Add(new Album(ID, AlbNm, Art, RelD, TrAmn, Loc, Rat));  
       currid++;
   }

I also added printing code:

   static public void printlist(List<Album>AlbumsList)
   {
       foreach (Album IDNumber in AlbumsList)
       {
           Console.WriteLine(Album.IDNumber + Album.AlbumName + Album.Artist + Album.ReleaseDate + Album.TrackAmount + Album.Location + Album.Rating);
       }
   }

Unfortunately it displays last "album" as many times as many different albums I have. Can anyone help me?

Jon Skeet
people
quotationmark

All your properties are static - that means that they are related to the type rather than any one instance of the type. (It's not that the values are "shared by all instance" - it's that they're completely unrelated to any instance.)

You should make them instance properties instead, just by removing the static modifier. You'll then need to change your foreach loop as well. Notice how in your current foreach loop you're completely ignoring your loop variable (IDNumber)? That's a hint that something's wrong. Try this instead:

// Variable and method names changed to be more readable and conventional.
// Modifier order also changed for convention.
public static void PrintList(List<Album> albums)
{
    foreach (Album album in albums)
    {
        Console.WriteLine(album.IDNumber + album.AlbumName + album.Artist + 
                          album.ReleaseDate + album.TrackAmount + album.Location + 
                          album.Rating);
    }
}

Or rather more pleasantly:

static public void PrintList(List<Album> albums)
{
    foreach (Album album in albums)
    {
        Console.WriteLine("{0} {1} {2} {3} {4} {5} {6}",
                          album.IDNumber, album.AlbumName, album.Artist,
                          album.ReleaseDate, album.TrackAmount, album.Location,
                          album.Rating);
    }
}

people

See more on this question at Stackoverflow