我想从同一个函数返回两个不同的值,但事实证明你只能返回1,但是围绕它有其他一些如使用元组和输出参数...我不明白如何构造它们和语法令人困惑。我尝试了几次,通过反复试验使其工作,但每次程序都没有启动。如果你能告诉我一个非常感激的解决方案。我设法返回string []卡,但现在我需要了解如何从同一函数返回int []值
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...
}
}
}
}
}
答案 0 :(得分:0)
public class Shuffled
{
public string[]cards{get;set;}
public int[] values{get;set;}
}
C#是一种面向对象的语言。返回包含函数数据的对象是很常见的。
static Shuffled ShuffleCardSystem()