This is the forum to discuss the Wrox book Beginning Visual C# 2005 by Karli Watson, Christian Nagel, Jacob Hammer Pedersen, Jon D. Reid, Morgan Skinner, Eric White; ISBN: 9780764578472
You are currently viewing the BOOK: Beginning Visual C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
1using System;
2using System.Collections.Generic;
3using System.Text;
4using Ch10CardLib;
5
6namespace Ch10CardClient
7{
8 class Program
9 {
10 static void Main(string[] args)
11 {
12 Deck myDeck = new Deck();
13 myDeck.Shuffle();
14 for (int i = 0; i < 52; i++)
15 {
16 Card tempCard = myDeck.GetCard(i);
17 Console.Write(tempCard.ToString());
18 if (i != 51)
19 Console.Write(", ");
20 else
21 Console.WriteLine();
22 }
23 Console.ReadKey();
24 }
25 }
26}
public Card GetCard(int cardNum)
{
if (cardNum >= 0 && cardNum <= 51)
return cards[cardNum];
else
throw (new System.ArgumentOutOfRangeException("cardNum", cardNum, "Value must be between 0 and 51."));
}
on line 16 Card tempCard = myDeck.GetCard(i);
GetCard return cards[cardNum]
how do you assign value of cards[cardNum] to tempCard? isn't tempCard is the variable type of Card?
If I understand your post correctly, the method GetCard does not return a Cards object. It returns a Card object from within the internal Cards collection of Deck. cards[cardNum] returns a Card object at the position within cards specified by cardNum.