/// <summary> /// Creates a deck using the selected deck size. /// </summary> /// <param name="size"></param> private void generateDeck(DeckSize size = DeckSize.FIFTY_TWO) { // the number of suits in a card deck const int NUMBER_SUITS = 4; int lowCard; if (size == DeckSize.TWENTY) { lowCard = (int)TWENTY_LOW_VALUE; // 10 is the low value in a 20 card deck } else if (size == DeckSize.THIRTY_SIX) { lowCard = (int)THIRTY_SIX_LOW_VALUE; // 6 is the low value in a 36 card deck } else if (size == DeckSize.FIFTY_TWO) { lowCard = (int)FIFTY_TWO_LOW_VALUE; // 2 is the low value in a 52 card deck } else { throw new System.ArgumentException("Cannot create a deck of size " + (size.ToString())); } // clear old deck clear(); // now re-allocate memory deck.Capacity = (int)size; // set the deck size field myDeckSize = size; // start with the lowest suit and add all values, than continue // doing the same with all other suits. for (int i = 0; i < NUMBER_SUITS; ++i) { for (int j = lowCard; j <= (int)Rank.ACE; ++j) { deck.Add(new Card((Suit)i, (Rank)j)); } } }