我知道方法用于分组代码,但我如何使用一种方法的先前功能与另一种方法。在Dealings()部分,我想在" 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()
{
}
}
答案 0 :(得分:0)
现在尝试使用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)
{
...
}
}