beefsupreme9731
beefsupreme9731
CC#
Created by Ghost_ on 12/28/2022 in #help
❔ Populating an Array with a Loop and then being able to call indexes
^ in the Main() program.
7 replies
CC#
Created by Ghost_ on 12/28/2022 in #help
❔ Populating an Array with a Loop and then being able to call indexes
Card myCardObject = new();

Console.WriteLine(myCardObject.Deck[2]);
Card myCardObject = new();

Console.WriteLine(myCardObject.Deck[2]);
7 replies
CC#
Created by Ghost_ on 12/28/2022 in #help
❔ Populating an Array with a Loop and then being able to call indexes
internal class Card
{
public string[] Deck { get; private set; } = PopulateDeck();

private static string[] PopulateDeck()
{
int deckCounter = 0;
string[] Values =
{
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"J",
"Q",
"K",
"A"
};

string[] Suits =
{
" of Hearts",
" of Diamonds",
" of Clubs",
" of Spades"
};

string[] returnArray = new string[52];

for (int i = 0; i < Values.Length; i++)
{
for (int j = 0; j < Suits.Length; j++)
{
returnArray[deckCounter] = Values[i] + Suits[j];
deckCounter++;
}
}

return returnArray;
}
}
internal class Card
{
public string[] Deck { get; private set; } = PopulateDeck();

private static string[] PopulateDeck()
{
int deckCounter = 0;
string[] Values =
{
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"J",
"Q",
"K",
"A"
};

string[] Suits =
{
" of Hearts",
" of Diamonds",
" of Clubs",
" of Spades"
};

string[] returnArray = new string[52];

for (int i = 0; i < Values.Length; i++)
{
for (int j = 0; j < Suits.Length; j++)
{
returnArray[deckCounter] = Values[i] + Suits[j];
deckCounter++;
}
}

return returnArray;
}
}
7 replies