开发者

How to check multiple condition for string data type using IF statement using && operator

开发者 https://www.devze.com 2023-03-03 17:00 出处:网络
Anyone please hel开发者_如何学JAVAp me, my problem is this i want to check in c#, more textbox values conditions using \'if\' statement like this,

Anyone please hel开发者_如何学JAVAp me, my problem is this i want to check in c#, more textbox values conditions using 'if' statement like this,

  if(txtbox1.Text == "" && txtbox2.Text == "" && ...&&txtboxN.Text =="")
  {
    MessageBox.Show("Please enter the details");
    return;
  }

but when i use more condition it is not taking the 'second' and others conditions.. what is the solution for this?


It sounds like you want or NOT and (i.e. swap the && for || ).


I think you want to use OR not AND:

if(txtbox1.Text == "" || txtbox2.Text == "" || ...||txtboxN.Text =="")

This will show the message box if at least one text box is empty.


You have to use &, not &&.
With && if first condition is false, other conditions are not evaluated at all.
Anyway for your example I think you should use ||, so if one of textboxes is empty your message is shown.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号