[英]Pathing methods and return types
我知道方法用于对代码进行分组,但是我如何将一种方法的先前功能与另一种方法结合使用。 在 Dealings() 的部分中,我想在“ShuffleCardSystem()”方法中使用卡 [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)
{
...
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.