I am putting 5 numbers into an array that are randomly generated. Each array can only have 5 sets of numbers. Depending on how many draws I want, lets say 5 it should print out something like this.
12345 //array 1
54321 //array 2
98765 //array 3
45678 //array 4
34589 //array 5
Then plop it into the List object and print it out.
When I debug the the thing it is working I see the list object being populated with all 5 arrays and the numbers in each element. But when I try to print the list out it just gives me the System.Int32[] output.
Here is my code, terribly written I know but I am just trying to get it to do the basic function, then I plan to clean it up and stuff.
I am basically trying to simulate the Mega Millions lottery kiosk. You select how many draws you want and then 5 sets of randomly generated numbers are printed out. The last statement of:
foreach (int[] g in list)
Console.WriteLine(" " + g);
This should work I don't know what is wrong and string.join("", g) does not work. It only prints out the first set of numbers in the first array. Believe me I googled this and I cannot find a solution. And since I got the functionality to work via debug, I don't want to waste hours trying to figure out why it won't print it out right.
static void Main(string[] args)
{
int[] getLotto = new int[5];
int getMega = 0;
Program p = new Program();
Console.WriteLine("MEGA MILLIONS!!\n");
p.result(ref getMega, ref getLotto);
for( int i = 0; i < 5; i++)
{
Console.Write(getLotto[i] + " ");
}
Console.WriteLine("\n\nMEGA {0}", getMega);
}
void result(ref int Mega, ref int[] storeNumArray)
{
var containter = new List<int>();
Random ranNumber = new Random();
int maxValue = 73;
int x = 0;
int y = 0;
int temp = 0;
int minValue = 1;
int draw = 5;
int[,] nDemension = new int[draw, 5];
List<int[]> list = new List<int[]>();
for(int s = 0; s < draw; s++)
for (int i = 0; i < 5; i++)
{
x = ranNumber.Next(minValue, maxValue);
storeNumArray[i] = x;
if (i == 4)
list.Add(storeNumArray);
}
while (y < 5)
{
Mega = ranNumber.Next(maxValue);
temp = storeNumArray[y];
if (Mega != temp)
{
y = 5;
break;
}
}
foreach (int[] g in list)
Console.WriteLine(" " + g);
}
}
}
string.Join(string.Empty, g)cannot work. It does exactly what you need.Console.WriteLine(" " + string.Join(string.Empty, g));