-5
 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.

Israel Meshileya
  • 293
  • 4
  • 18
  • 1
    Hover over `unchecked` and see what the error is saying. `unchecked` is a reserve word and it expects a context. The other thing is that to check equality use `==` – Habib Aug 09 '16 at 15:44
  • [unchecked is a keyword](https://msdn.microsoft.com/en-us/library/a569z7k8.aspx); `Catz = unchecked` does not make sense syntactically. Are you trying to use it as a variable? Or are you trying to really do something with overflow checking? – Jacob Aug 09 '16 at 15:45
  • im using the if statement to perform actions based of if the checkbox is checked or not – Jesse Brand Aug 09 '16 at 15:49
  • Is `Catz` the name of your checkbox? – itsme86 Aug 09 '16 at 15:50
  • Yes it is that's what im trying to determine the result of – Jesse Brand Aug 09 '16 at 15:52
  • the more information you supply the better answers you get. And people get less confused when trying to help you :) – Mong Zhu Aug 09 '16 at 15:56

2 Answers2

3

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
}
Mong Zhu
  • 23,309
  • 10
  • 44
  • 76
0

You have 2 problems in the code you show:

1) = is for assignment, == is for checking equality. You have = when you should be using ==.

2) unchecked is a keyword in C#. You can use keywords as variable names if you prepend an @ to it:

if (Catz == @unchecked)

It's easier to just use an unreserved variable name though.

itsme86
  • 19,266
  • 4
  • 41
  • 57