日期:2014-05-18  浏览次数:20812 次

提取枚举值问题
using System; 
using System.Collections.Generic; 
using System.Text; 


namespace ConsoleApplication1 

  public enum Suit 
  { 
  红心, 
  梅花, 
  方片, 
  黑桃, 
  } 
  public enum Rank 
  { 
  Ace, 
  Deuce, 
  Three, 
  Four, 
  Five, 
  Six, 
  Seven, 
  Eight, 
  Nine, 
  Ten, 
  Jack, 
  Queen, 
  King 
  } 
  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); 
  } 
  } 
  } 
  public Card GetCard(int cardNum) 
  { 
  if (cardNum >= 0 && cardNum <= 51) 
  return cards[cardNum]; 
  else 
  throw new System.ArgumentOutOfRangeException("错误!!!"); 
  } 
  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); 
  } 
  } 
  public class Card 
  { 
  public readonly Rank rank; 
  public readonly Suit suit; 
  public Card(Suit newSuit, Rank newRank) 
  { 
  suit = newSuit; 
  rank = newRank; 
  } 
  private Card() 
  { 
  throw new System.NotImplementedException(); 
  } 
  public override string ToString() 
  { 
  return suit + "" + rank; 
  } 
  } 
  class Program 
  { 
  static void Main(string[] args) 
  { 
  Deck myDeck=new Deck(); 
  m