我想從同一個函數返回兩個不同的值,但事實證明,您只能返回1,但其他人也可以使用元組和外部參數......我不想不理解如何構造它們,語法很混亂。我嘗試過多次嘗試,通過反覆試驗,但每次程序甚至沒有開始。如果你能向我展示一個非常感謝的解決方案。我設法返回字符串[]卡,但現在我需要了解我怎麼可以從相同的功能來自同一函數的多個不同的返回類型
namespace Testing2._0
{
class Program
{
static void Main(string[] args)
{
string[] cards = ShuffleCardSystem();
Dealing(cards);
Format();
Console.ReadLine();
}
static void Format()
{
//Not important
}
}
static string [] ShuffleCardSystem()
{
string[] ranks = new string[13] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" };
int rankCounter = 0;
string []suits = new string[4] { "♠", "♣", "♦", "♥" };
int suitsCounter = 0;
int shuffle; string temp;
Random rnd = new Random();
int[] value = new int[52];
string numbers = string.Empty;
int convert;
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--)
{
numbers= string.Empty;
shuffle = rnd.Next(0, i);
temp = cards[shuffle];
cards[shuffle] = cards[i];
cards[i] = temp;
for (int position =0; position<cards[i].Length; position++)
{
if (char.IsDigit(cards[i][position]))
{
numbers+=cards[i][position];
convert= Convert.ToInt32(numbers);
value[i]= convert;
if (value[i] ==1)
{
value [i]=11;
}
}
if (cards[i].Any(char.IsLetter))
{
value[i] = 10;
}
}
}
}
return cards; // I want to return value
}
static void Dealing(string[] cards)
{
//other unrelated code...
}
}
}
}
}
你爲什麼不回班? –
嘗試返回對象數組。 –