[英]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.