T
Thomas Neubauer
Hello,
i am learning c# and have created now a simple project that just creates 6
random numbers.
My form includes a button and 6 labels for the random numbers. The program
seems to work correct,
however when after a few button clicks the program crashes.
Does anyone know where the reason could be?
--
Kind regards
Thomas Neubauer
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btZieheLottozahlen_Click(object sender, EventArgs e)
{
int[] Zahlen = new int[6];
Random Zufallszahl = new Random();
int Doppelte = 0;
do
{
for (int i = 0; i < 6; i++)
{
Zahlen = Zufallszahl.Next(1, 64);
}
Array.Sort(Zahlen);
for (int i = 0; i < 5; i++)
if (Zahlen == Zahlen[i + 1])
Doppelte = 1;
} while (Doppelte == 1);
label1.Text = Convert.ToString(Zahlen[0]);
label2.Text = Convert.ToString(Zahlen[1]);
label3.Text = Convert.ToString(Zahlen[2]);
label4.Text = Convert.ToString(Zahlen[3]);
label5.Text = Convert.ToString(Zahlen[4]);
label6.Text = Convert.ToString(Zahlen[5]);
}
}
}
i am learning c# and have created now a simple project that just creates 6
random numbers.
My form includes a button and 6 labels for the random numbers. The program
seems to work correct,
however when after a few button clicks the program crashes.
Does anyone know where the reason could be?
--
Kind regards
Thomas Neubauer
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btZieheLottozahlen_Click(object sender, EventArgs e)
{
int[] Zahlen = new int[6];
Random Zufallszahl = new Random();
int Doppelte = 0;
do
{
for (int i = 0; i < 6; i++)
{
Zahlen = Zufallszahl.Next(1, 64);
}
Array.Sort(Zahlen);
for (int i = 0; i < 5; i++)
if (Zahlen == Zahlen[i + 1])
Doppelte = 1;
} while (Doppelte == 1);
label1.Text = Convert.ToString(Zahlen[0]);
label2.Text = Convert.ToString(Zahlen[1]);
label3.Text = Convert.ToString(Zahlen[2]);
label4.Text = Convert.ToString(Zahlen[3]);
label5.Text = Convert.ToString(Zahlen[4]);
label6.Text = Convert.ToString(Zahlen[5]);
}
}
}