In the method h()
, the while
forms an infinite loop if the atk!=10
. so you need to specify an exit condition there to break the loop; you can use like this:
public void h()
{
while (Atk != 10)
{
this.Atk = random.Next(11);
}
Console.WriteLine(Atk);
}
Now you will get a random number between 0 and 11 and is not 10
in the console
1
solved random number in constructor c#