路径方法和返回类型

本文关键字:返回类型 方法 路径 | 更新日期: 2023-09-27 18:20:59

我知道方法是用来对代码进行分组的,但我如何将一个方法的前一个函数与另一个方法一起使用呢。在Dealing()的部分中,我想使用"ShuffleCardSystem()"方法中的cards[i]来处理数组的每个奇数位置。我知道我必须使用正确的返回类型和声明,但每次尝试都会以错误告终。

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()
    {
    }
}

路径方法和返回类型

暂时尝试使用string[]作为返回类型:

  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)
       {
           ...
       }
  }