Skip to content
Loading
  • Dharmraj Thakur
    +1
    I implement your code... its working fine, Where is the issue?
     
    1. class Card  
    2. {  
    3.     public Card(Suits suit, Values value)  // This constructor has integer values sent to it    
    4.     {  
    5.         this.Suit = suit;  
    6.         this.Value = value;  
    7.     }  
    8.   
    9.     public Suits Suit { get; set; }  
    10.     public Values Value { get; set; }  
    11.   
    12.     public string Name  
    13.     {  
    14.         get  
    15.         {  
    16.             //return Value.ToString() + " of " + Suit.ToString();  // The integer values can be converted to their reference names    
    17.             return (Values)Value + " of " + (Suits)Suit;  // Here's another way of doing it - Casting to their type, not to string    
    18.         }  
    19.     }  
    20. }  
    21.   
    22. enum Suits  
    23. {  
    24.     Hearts,     // 0         'Hearts' is of type Suits    
    25.     Clubs,      // 1    
    26.     Diamonds,   // 2    
    27.     Spades      // 3    
    28. }  
    29.   
    30. enum Values  
    31. {  
    32.     Ace = 1,                // 'Ace' is of type Values    
    33.     Two = 2,  
    34.     Three = 3,  
    35.     Four = 4,  
    36.     Five = 5,  
    37.     Six = 6,  
    38.     Seven = 7,  
    39.     Eight = 8,  
    40.     Nine = 9,  
    41.     Ten = 10,  
    42.     Jack = 11,  
    43.     Queen = 12,  
    44.     King = 13  
    45. }  
    46.   
    47. class Program  
    48. {  
    49.     static void Main(string[] args)  
    50.     {  
    51.         InitializePack();  
    52.         Console.ReadKey();  
    53.     }  
    54.     public static void InitializePack()  
    55.     {  
    56.         Card[] pack = new Card[52];  
    57.         for (int i = 0; i < 4; i++)  
    58.         {  
    59.             for (int j = 1; j < 14; j++)  
    60.             {  
    61.                 pack[(i * 13) + j - 1] = new Card((Suits)i, (Values)j);  
    62.             }  
    63.         }  
    64.         foreach (Card c in pack)  
    65.             Console.WriteLine(c.Name);  
    66.     }  
    67. } 
     
    +1