Ok, its me again. I am trying to mold my brain into thinking in Codese and I thought I had a decent way of creating a Deck of Cards.
Everything was working and seem to be going fine when BLAM! - I get an out of bounds of array exception.
I have two arrays (One with the Suits of the cards and one with the Numbers or Ranks of the Cards) -- then I was iterating through them and creating a new object that added the two arrays together.
**BTW - I am SURE there are a million better ways to do what I am trying but I am trying to create this with what I have right now in my brain**
Anyway, I create the object then write it to the screen and begin the next iteration. It was filling up nicely -- THREE SUITS were completely filled up and the fourth one was filling up BUT when it gets to the 10th value of the Rank array I get an Exception - Index out of bounds of Array - error.
It doesnt make any sense to me because I have gone BEYOND the 10th value 3 times already in the other suits. --
--- CAN SOMEONE give me a clue why I am getting this? ---
============
here is the code.
namespace ConsoleApplication1
{
{
class card
{
public string suit = "Clubs";
public string rank = "One";
public string[] Suits = new string[] { "h", "d", "c", "s" };
public string[] Ranks = new string[] { "A", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" };
}
}
class Program
{
static void Main(string[] args)
{
card mycard = new card();
string card = mycard.rank + " of " + mycard.suit;
string[] cards = new string[52];
int s;
int r;
int i = 0;
for (s = 0; s < 5; s++)
{
for (r = 0; r < 14; r++)
{
cards[i] = mycard.Suits[s] + " of " + mycard.Ranks[r];
Console.WriteLine(cards[i]);
i++;
}
}
}
}
}