Monday Instructions

We’re going to work learn the if block and the foreach block today.  But first, we’ll do a little bit of review.  We’re going to make an application that can handle a deck of cards.

The instructions:

  1. Open Visual C# Express and create a new Windows Forms application named SimpleCardApp
  2. Create a new class named “Card”
  3. Give your Card class the following properties:
  • Suit (string)
  • NumericValue (int)
  • FaceValue (string)


Once that’s done, do the following:

  1. Go to the code behind of the Form1.cs
  2. Add a private property which is a List<Card> called Deck
  3. Create a private method named FillDeck which returns nothing and takes no parameters
  4. Type the following:
Deck = new List<Card>();
string[] suits = { "Spades", "Hearts", "Clubs", "Diamonds" };
int numericValue = 0;
 foreach (string suit in suits)
 if (numericValue == 14)
 numericValue = 1;
Card newCard = new Card();
 newCard.Suit = suit;
 newCard.NumericValue = numericValue;
 newCard.FaceValue = numericValue.ToString();
if (numericValue == 1)
 newCard.FaceValue = "Ace";
 if (numericValue == 11)
 newCard.FaceValue = "Jack";
 if (numericValue == 12)
 newCard.FaceValue = "Queen";
 if (numericValue == 13)
 newCard.FaceValue = "King";



Leave a Reply

Your email address will not be published. Required fields are marked *