So I am adding/creating objects within Console class via an array:
string[] console_available = { "Yes", "Yes", "Yes", "Yes", "Yes" };
for (int i = 0; i < console_available .Length; i++)
{
Classes.Console console = new Classes.Console(console_available[i]);
}
In the class itself I have int console_id which I want to increment but for some reason it only increments it once with the below constructor:
public int ConsoleID { get; set; } = 0;
public string Available { get; set; }
public Console(string available)
{
ConsoleID++;
this.Available = available;
}
So in essence its all "1 Yes" where I need it to be "1 Yes", "2 Yes", "3 Yes".
I don't really want to go down the route of having multiple lines of code to create the objects, e.g.:
Classes.Console console = new Classes.Console("Yes");
Classes.Console console2 = new Classes.Console("Yes");
Classes.Console console3 = new Classes.Console("Yes");
ConsoleIDis specific to each instance. Your constructor is adding to the variable but every time you declare a new instance, it just sets it back to 0 since that's hard coded. Make it into astaticvariable like @Sean answered to solve this.