Here's my code thats throwing an error saying Cannot convert type "int" to Cards.Suits and 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); } } } the cards constructor is
public readonly Suits suit; public readonly Rank rank; public Card(Suits newSuit, Rank newRank) { suit = newSuit; rank = newRank; } Now the Suits enum and Rank enum are as a regular deck of cards starting at ACE = 1 so on and suits are DIAMONDS, CLUBS, HEARTS, SPADES. Can anyone tell me why im getting the above error. The following code was taking from a book. Thanks!
*EDIT
public enum ranks { ACE = 1, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING, } public enum Suit { DIAMOND, CLUB, HEART, SPADE, }
SuitsandRank?(Suits)suitValbut the enum you posted is actually namedSuit.ranksandSuit, but attempts to cast to typesRankandSuits. Make sure all of your type names match up.