Getting Error Msg - Cannot implicitly convert type 'string' to 'bool'

后端 未结 5 2023
刺人心
刺人心 2020-12-20 09:16

I am checking for values in a textbox to trigger a conditional statement, but am getting error messages.

if (txtAge.Text = \"49\") || (txtAge.Text = \"59\")
         


        
5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-20 09:36

    Need to use == instead of =. Former is used for comparison while the later is for assignment.

    A better way is to use Equals method

    if (txtAge.Text.Equals("49") || txtAge.Text.Equals("59"))
    { 
    }
    

提交回复
热议问题