views:

184

answers:

4

Hi,

I want to hide some things when the value of the numericUpDown is changed so I wrote this:

        if (numericUpDown1.Value = 1)
        {
            Label1.Hide();
        }

but I get this error message:

Cannot implicitly convert type 'decimal' to 'bool'

Thanks

+8  A: 

I think you mean "if (numericUpDown1.Value == 1)".

In most languages, "==" is the test for equality, while "=" is the assignment operator.

Zach Scrivena
more evidence of a facepalm tag required :)
annakata
or a "D'oh!" tag =)
Zach Scrivena
+1  A: 

You're not performing a comparison (change = to ==) ... Try:

if (numericUpDown1.Value == 1)
{
    Label1.Hide();
}
bruno conde
+2  A: 

What language are you using with the single "=" sign? In VB you would be comparing and in C# you would be assigning a number with an "if" statement. A way to protect yourself from this would be to list the number first: if (1 = numericUpDown) which would be fine if comparing was allowed in that language and bad you had intended to make an assignment. The mistake would jump out at you!

A: 

the "==" Worked

thank you!