Operator && Error

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

When running the following code:

if (typeCheck.Checked == true && typeList.SelectedItem == "3")
{
return " and wopm3 = '3' or wopm3 = '3C' or wopm3 = '3I'";
}

I get the following error:

Operator '&&' cannot be applied to operands of type 'bool'

Hoiw can I alter my code to handle this error?

Thanks,

Dave
 
Dave Bailey said:
When running the following code:

if (typeCheck.Checked == true && typeList.SelectedItem == "3")
{
return " and wopm3 = '3' or wopm3 = '3C' or wopm3 = '3I'";
}

I get the following error:

Operator '&&' cannot be applied to operands of type 'bool'

Hoiw can I alter my code to handle this error?

Well, this simplest transformation of the above is:

if ((typeCheck.Checked==true) && (typeList.SelectedItem=="3"))

However, I would expect the above to compile okay, to be honest. Could
you post a short but complete program which demonstrates the problem?
 
Hi Dave,


I assumed that typeCheck is a checkbox & typeList is a DropDownList/ComboBox
or Listbox
If so I got a warning saying that "Possible unintended reference
comparison; to get a value comparison, cast the left hand side to type
'string'" refering to the comparision between a object ( SelectedItem ) and
a string.

Cheers,
 
Try
if ((typeCheck.Checked == true) && (typeList.SelectedItem == "3"))
{
return " and wopm3 = '3' or wopm3 = '3C' or wopm3 = '3I'";
}
if it is what you wanted
 
Back
Top