Jesse Brand Jesse Brand - 4 months ago 11
C# Question

Error on if statement when using unchecked

if (Catz = unchecked)


It shows an error after the
")"
at the end of this statement. I have the whole statement written out and it shows no other errors besides asking for another
")"
.

Is there an issue with using unchecked?
NOTE: I have a checkbox that I'm using for this if statement.

Answer

try this:

if (Catz.Checked)
{
    // do whatever
}

If I understood you correctly and Catz is a CheckBox then the property you are looking for is probably Checked. This can be true or false In an if statement you can use the bool variable without a comparison operator like "=="

to check for the opposite use the "!" negation operator:

// if UNCHECKED / NOT CHECKED
if (!Catz.Checked)
{
    // do whatever
}