1 Replies - 235 Views - Last Post: 23 January 2013 - 03:03 AM Rate Topic: -----

#1 inkey  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 49
  • Joined: 26-June 12

C# Or Operator Problem

Posted 23 January 2013 - 02:45 AM

I am having a problem where i am trying to check if two label values are equal too null. One of the labels is null and the other contains a string value. The code i have seems to only check if one of the labels is empty and not the other.
heres the statement in question
if (string.IsNullOrEmpty(Lbl1.Text) || string.IsNullOrEmpty(Lbl2.Text))
            {
               messagebox.show("Boxes Empty");
            }
            else
            {
              messagebox.show("Boxes not empty");
            }


Can anyone see why it would not be hitting the else if Lbl2 has a value.

Thanks Inkey

Is This A Good Question/Topic? 0
  • +

Replies To: C# Or Operator Problem

#2 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1010
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: C# Or Operator Problem

Posted 23 January 2013 - 03:01 AM

Think about it. If Lbl1.Text is empty then the result is true, it doesn't matter what is in Lbl2.Text. If you want to check if *both* are empty, use and (&&).
Was This Post Helpful? 3
  • +
  • -

Page 1 of 1