Pathing方法和返回类型

问题描述:

我知道方法用于组代码,但我如何使用另一个方法的以前的功能。在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() 
    { 

    } 
} 

尝试使用字符串[]作为现在您的返回类型:

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循环。谢谢您的帮助。我真的很感激@詹姆斯 –