andrew woolgar

andrew woolgar

  • NA
  • 9
  • 540

ArgumentOutOfRangeException was unhandles error

May 9 2020 3:46 PM
Gid day all,
 
I am still learning C#
 
I have been seeking to modify an poker game tutorial from using an array to using a list for the deck of cards.
  1. class DeckOfCards : Card  
  2. {  
  3. const int NUM_OF_CARDS = 24; // number of all cards  
  4. private List<Card> deck; //list of all palying cards  
  5. public DeckOfCards()  
  6. {  
  7. deck = new List<Card>(NUM_OF_CARDS);  
  8. }  
  9. public List<Card> getDeck { get { return deck; } } //get current deck  
  10. //create deck of 24 cards: 6 values with 4 suits  
  11. public void setUpDeck()  
  12. {  
  13. int i = 0;  
  14. foreach(SUIT s in Enum.GetValues(typeof(SUIT)))  
  15. {  
  16. foreach (VALUE v in Enum.GetValues(typeof(VALUE)))  
  17. {  
  18. deck[i] = new Card { MySuit = s, MyValue = v };  
  19. i++;  
  20. }  
  21. }  
  22. ShuffleCards();  
  23. }  
I keeping getting ArgumentOutOfRangeException was unhandles error for deck[i] =new Card { MySuit = s, MyValue = v};
 
How do I change the argument for array to issue
 
Thank you for help in advance

Answers (1)