So i have this int that is being a pain in the ***
int ir = rnd.Next(0, 100);
...and the compiler complains:
"Error CS0236 A field initializer cannot reference the non-static field, method, or property 'Main.rnd'"
Here's the code with the Random class
public Main()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e){}
int startb = 0;
int setb = 0;
int quitb = 0;
int b4 = 0;
Random rnd = new Random();
int ir = rnd.Next(0, 100);
There is only one rnd object and only one Random in the project and those two lines are in the same Main.cs
Sorry if i'm asking about what has already been explained because i couldn't seem to find any answer to this anywhere.
Aucun commentaire:
Enregistrer un commentaire