I have already received this problem a few times, i wonder why i can't use my index in the switch, i receive an error that the array[index] = null, any reason why?
// array of classes, im using public getters and setters to access the rank and cardcolor
Cardgame[] cardgame = new Cardgame[50];
int index = 0;
string CardColor = "";
...
for (int i = 0; i < 4; i++)
{
switch (i)
{
case 1: CardColor = "red";
break;
case 2: CardColor = "blue";
break;
case 3: CardColor = "diamond";
break;
case 4: CardColor = "candy!";
break;
}
for (int x = 0; x <= 13; x++)
{
index++;
Cardgame[index].Color = CardColor;
switch (x)
{
default: Cardgame[index].Number = x.ToString();
break;
case 11: Cardgame[index].Number = "Farmer";
break;
case 12: Cardgame[index].Number = "Queen";
break;
case 13: Cardgame[index].Number = "King";
break;
}
}
new Cardgame[50]initializes aCardgamearray with 50nulls. Are you creating 50new Cardgames to fill the array after that?for (int i = 0; i <= 4; i++)should befor (int i = 1; i <= 4; i++)