I know that methods are used to group codes, but how do i use the previous function of one method with another. In the section of Dealings() i want to use cards[i] in the "ShuffleCardSystem()" methods to deal out every odd position of the array. I know I have to use proper return types, and declaration, but every i tried to do it, it always ended in error.
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()
{
}
}
Try using string[] as your return type for now:
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)
{
...
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.