当我创建一个类型的对象时Deck
,会显示一个异常:“indexoutofrangeexception 未处理”
有人可以解释为什么吗?
public class Deck {
Card[] card = new Card[52];
const int NumOfCards = 52;
public Deck()
{
string[] symbol = { "Diamonds", "Clubs", "Hearts", "Spades"};
string[] rank = { "Ace", "Two", "Three", "Four", "Five", "Six",
"Seven", "Eight", "Nine", "Jack", "Queen", "King"};
for (int i = 0; i < card.Length; ++i)
{
/// this is the line with problem shown in debug
card[i] = new Card(symbol[i / 13], rank[i % 13]);
}
Console.WriteLine(card.Length);
}
public void PrintDeck() {
foreach (Card c in card)
Console.WriteLine(c);
}
}