2015-11-07 23 views
-1

我知道方法用於組代碼,但我如何使用另一個方法的以前的功能。在Dealings()部分中,我想在「ShuffleCardSystem()」方法中使用cards [i]來處理數組中的每個奇數位置。我知道我必須使用正確的返回類型和聲明,但是我每次都試圖這樣做,它總是以錯誤結尾。Pathing方法和返回類型

class Program 
{ 
    static void Main(string[] args) 
    { 
     ShuffleCardSystem(); 
     Dealings(); 

     Console.ReadLine(); 

    } 
    static void ShuffleCardSystem() 
    { 
     List<string> ranks = new List<string> 
     { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" }; 
     int rankCounter = 0; 
     List<string> suits = new List<string> { "♠", "♣", "♦", "♥" }; 
     int suitsCounter = 0; 
     int shuffle; string temp; 
     Random rnd = new Random(); 
     int[] value = new int[52]; 
     string numbers = string.Empty; 
     string s = string.Empty; 
     string[] cards = new string[52]; 
     for (int i = 0; i < 52; i++) 
     { 
      cards[i] = ranks[rankCounter] + suits[suitsCounter]; 
      rankCounter++; 
      if (rankCounter == 13) 
      { 
       rankCounter = 0; 
       suitsCounter += 1; 
      } 
     } 
     for (int i = 51; i >= 0; i--) 
     { 
      shuffle = rnd.Next(0, i); 
      temp = cards[shuffle]; 
      cards[shuffle] = cards[i]; 
      cards[i] = temp; 
      Console.Write(cards[i] + " "); 
     } 
    } 
    static void Dealing() 
    { 

    } 
} 

回答

0

嘗試使用字符串[]作爲現在您的返回類型:

class Program 
    { 
     static void Main(string[] args) 
     { 
      var cards = ShuffleCardSystem(); 
      Dealings(cards); 

      Console.ReadLine(); 

     } 
     static string[] ShuffleCardSystem() 
     { 
      //existing code 
      return cards; 
     } 
     static void Dealing(string[] cards) 
     { 
      ... 
     } 
    } 
+0

靜態字符串[] ShuffleCardSystem()存在洗牌系統錯誤它說,不是所有的路徑返回一個值@詹姆斯 –

+0

請確保'返回卡;'是你的方法的最後一行 – James

+0

哦哇,我是一個白癡,我不小心把一個for循環。謝謝您的幫助。我真的很感激@詹姆斯 –