c#入门经典 扑克牌程序中的一个问题
各位大神,目前刚自学c#,但是在第十章扑克牌程序卡住了,遇到了个问题,如下:using System;
using System.Collections.Generic;
using System.Text;
namespace Ch10CardLib
{
public enum Suit
{
Club,
Diamond,
Heart,
Spade,
}
public enum Rank
{
Ace = 1,
Deuce,
Three,
Four,
Five,
Six,
Seven,
Eight,
Nine,
Ten,
Jack,
Queen,
King,
}
public class Card
{
public readonly Suit suit;
public readonly Rank rank;
public Card(Suit newSuit,Rank newRank)
{
this.suit = newSuit;
this.rank = newRank;
}
private Card() { }
public override string ToString()
{
return "The " + rank + " of " + suit + "s";
}
}
public class Deck
{
private Card[] cards;
public Deck()
{
cards = new Card[52];
for (int suitVal = 0; suitVal < 4; suitVal++)
{
for (int rankVal = 1; rankVal < 14; rankVal++)
{
cards[suitVal * 13 + rankVal - 1] = new Card((Suit)suitVal,(Rank)rankVal);
}
}
}
[color=#FF0000]public Card GetCard(int cardNum)
{
if (cardNum >= 0 && cardNum <= 51)
return cards[cardNum ];
else
throw (new System.ArgumentOutOfRangeException("cardNum", cardNum, "数字在0-51间"));
}[/color]
public void Shuffle()
{
Card[] newDeck = new Card[52];
bool[] assigned=new bool[52];
Random sourceGen = new Random();
for (int i = 0; i < 52; i++)
{
int destCard = 0;
bool foundCard = false;
while (foundCard == false)
{
destCard = sourceGen.Next(52);
if (assigned[destCard] == false)
foundCard = true;
}
assigned[destCard] = true;
newDeck[destCard] = cards[i];
}
newDeck.CopyTo(cards ,0);
}
}
}
创建GetCard方法时,VS2010显示错误“.Deck.GetCard(int)”: 并非所有的代码路径都返回值,求解,输入几次都显示这种错误?