Hey all,
I am having trouble with one of my programs im trying to make with random class. I am a begginer of C# and was wondering if someone can point me in the right direction.
Random x = new Random();
int randomNumber = x.Next(1, 5);
labelNumber.Text +=
randomNumber + "";
That is my code to generate a number so I can assign it to an if statement eg.
if ( labelNumber = 1)
outputBox.Text = "You won"
etc. etc.
I cant get it to work because it says
Error 1 Cannot implicitly convert type 'int' to 'System.Windows.Forms.Label'
Error 2 Cannot implicitly convert type 'System.Windows.Forms.Label' to 'bool'
If anyone can help me I would really appreciate it.
Thanks!!
Loading
kindra dragonPosted Mar 23, 2008, 6:55 AM
Thanks guys
AlanPosted Mar 23, 2008, 5:13 AM
In C#, '=' is an assignment operator. The equality operator is '==' so that line needs to be:
if (labelNumber.Text == x.ToString() )
kindra dragonPosted Mar 23, 2008, 1:01 AM
int x = 1;
if (labelNumber.Text = x.ToString() )
outPut.Text = "Yes you win!)";
I am still getting Error 1 Cannot implicitly convert type 'string' to 'bool'
Bechir BejaouiPosted Mar 22, 2008, 9:53 AM
Bechir BejaouiPosted Mar 22, 2008, 9:52 AM
I mean
int x = 2;
textBox.Text = x // This peace of code generates a code
but you have to do as so
textBox.Text = Convert.ToString(x);
or simply
textBox.Text = x.ToString();