c# - Operator '>' cannot be applied to operands of type 'bool' and 'bool' -


i've reverse engineered application i've lost source code , unable past error being thrown upon building application.

the error: "operator '>' cannot applied operands of type 'bool' , 'bool' "

on line

this.listbox1.selectedindex = ((-(((this.listbox1.selectedindex == 1) > false) ? 1 : 0)) ? 1 : 0); 

where

this.listbox1.selectedindex == 1) > false 

any appreciated. thanks!

your error message says all

operator '>' cannot applied operands of type 'bool' , 'bool'

there no concept of order boolean in c#. 2 boolean values either equal, or unequal.

if trying case

this.listbox1.selectedindex == 1 

is not true, instead use

this.listbox1.selectedindex != 1 

for example

this.listbox1.selectedindex = (this.listbox1.selectedindex != 1) ? 0 : 1; 

or equivalently , easier read

this.listbox1.selectedindex = (this.listbox1.selectedindex == 1) ? 1 : 0; 

this code leave selected index @ 1 if 1, , set 0 other value.


Comments