这是我的代码,它抛出一个错误说Cannot convert type "int" to Cards.Suits
和
Cannot convert type "int" to Cards.Rank
private Card[] cards;
public Deck()
{
cards = new Card[52];
for (int suitVal = 0; suitVal < 4; suitVal++)
{
for (int rankVal = 0; rankVal < 14; rankVal++)
{
cards[suitVal * 13 + rankVal - 1] = new Card((Suits)suitVal, (Rank)rankVal);
}
}
}
卡片构造函数是
public readonly Suits suit;
public readonly Rank rank;
public Card(Suits newSuit, Rank newRank)
{
suit = newSuit;
rank = newRank;
}
现在 Suits 枚举和 Rank 枚举是从 ACE = 1 开始的常规牌组,以此类推,花色是 DIAMONDS、CLUBS、HEARTS、SPADES。谁能告诉我为什么我得到上述错误。以下代码取自一本书。谢谢!
*编辑
public enum ranks
{
ACE = 1,
TWO,
THREE,
FOUR,
FIVE,
SIX,
SEVEN,
EIGHT,
NINE,
TEN,
JACK,
QUEEN,
KING,
}
public enum Suit
{
DIAMOND,
CLUB,
HEART,
SPADE,
}