C# 路径方法和返回类型
我知道方法用于分组代码,但如何将一种方法的上一个函数与另一种方法一起使用。在deactions()一节中,我想使用“ShuffleCardSystem()”方法中的cards[i]来处理数组中的每个奇数位置。我知道我必须使用正确的返回类型和声明,但每次我尝试这样做时,总是以错误告终C# 路径方法和返回类型,c#,methods,return-type,C#,Methods,Return Type,我知道方法用于分组代码,但如何将一种方法的上一个函数与另一种方法一起使用。在deactions()一节中,我想使用“ShuffleCardSystem()”方法中的cards[i]来处理数组中的每个奇数位置。我知道我必须使用正确的返回类型和声明,但每次我尝试这样做时,总是以错误告终 class Program { static void Main(string[] args) { ShuffleCardSystem(); Dealings();
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()
{
}
}
类程序
{
静态void Main(字符串[]参数)
{
ShuffleCardSystem();
交易();
Console.ReadLine();
}
静态无效ShuffleCardSystem()
{
列表等级=新列表
{“1”、“2”、“3”、“4”、“5”、“6”、“7”、“8”、“9”、“10”、“J”、“Q”、“K”};
int rankCounter=0;
列表套装=新列表{”♠", "♣", "♦", "♥" };
int suitsCenter=0;
int-shuffle;字符串温度;
随机rnd=新随机();
int[]值=新的int[52];
字符串编号=string.Empty;
string s=string.Empty;
字符串[]卡片=新字符串[52];
对于(int i=0;i<52;i++)
{
卡片[i]=等级[rankCounter]+套装[suitsCounter];
rankCounter++;
如果(rankCounter==13)
{
rankCounter=0;
SuitsCenter+=1;
}
}
对于(int i=51;i>=0;i--)
{
shuffle=rnd.Next(0,i);
临时=牌[洗牌];
牌[洗牌]=牌[i];
卡片[i]=临时工;
控制台。写(卡片[i]+“”);
}
}
静态无效处理()
{
}
}
现在尝试使用字符串[]作为返回类型:
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)
{
...
}
}
静态字符串[]ShuffleCardSystem()shuffle cards系统中有一个错误,它说并非所有路径都返回值@JamesMake sure
返回卡;
是该方法的最后一行哦,哇,我是个白痴,我无意中加入了for循环。谢谢你的帮助。我真的很感激@James