I get the error below when I try to run the application I am sure its something simple but I dont see it. What I am trying to do it when I click a button I have labeled Play. I want to call a method called randomnumber. Then I want the results to be displayed in lblPickFive_1.
I have 2×2,Pick5,and powerball. Each random number is to be displayed in its own label I created.
For now I am just looking to get past the one of generating a random number and having it displayed in the one label then I will move onto the rest. And I am sure post more questions if I cant figure out the rest.
Error 1 No overload for method 'RandomNumber' takes '0' arguments
using System;
using System.Windows.Forms;
namespace LotteryTickets
{
public partial class Form1 : Form
{
/// <summary>
/// no-args Constructor
/// </summary>
public Form1()
{
InitializeComponent();
}
#region "== Control Event Handlers =="
private void Form1_Load(object sender, EventArgs e)
{
ClearWinningNumbers();
}
#endregion "== End Control Event Handlers =="
#region "== Methods ==";
/// <summary>
/// Clears the text inside the winning number "balls"
/// </summary>
private void ClearWinningNumbers()
{
this.lblPickFive_1.Text = "";
this.lblPickFive_2.Text = "";
this.lblPickFive_3.Text = "";
this.lblPickFive_4.Text = "";
this.lblPickFive_5.Text = "";
this.lblTwoByTwo_1.Text = "";
this.lblTwoByTwo_2.Text = "";
this.lblPowerball_1.Text = "";
this.lblPowerball_2.Text = "";
this.lblPowerball_3.Text = "";
this.lblPowerball_4.Text = "";
this.lblPowerball_5.Text = "";
this.lblPowerball_PB.Text = "";
}
#endregion "== End Methods ==";
private void cblTwoByTwo_2_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void cblTwoByTwo_1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void btnPlay_Click(object sender, EventArgs e)
{
RandomNumber();
}
private void lblPickFive_1_Click(object sender, EventArgs e)
{
}
private void RandomNumber(int min, int max)
{
int num = new Random().Next(min, max);
lblPickFive_1.Text = num.ToString();
}
}
}
Best Answer
First, you shouldn't be newing up a random number generator every time you want a new random number. You should set the generator as a static or member variable and refer to it for each new number.
Second, you have to pass a min and a max to your
RandomNumber
method.