I have consistently had problems with the OR (and the AND) operator. I have tried the short circuited and non-short circuited OR operator and I just cannot get it to work properly. It just will not fall into the IF statement. Something like the following: if
((mystring == "aa") || (mystring == "bb")) { //do something }
I have consistently had problems with the OR (and the AND) operator. I have tried the short circuited and non-short circuited OR operator and I just cannot get it to work properly. It just will not fall into the IF statement. Something like the following: if
((mystring == "aa") || (mystring == "bb")) { //do something }
In fact, I don't recommend you use the operator "==" beacuse it compares the strings values, but in some cases it will be fails. Why don't use the method equals?
mrrogers
Member
203 Points
733 Posts
Problems with the "||" OR operator
Oct 20, 2008 12:24 PM|LINK
gbogea
Contributor
4019 Points
576 Posts
Re: Problems with the "||" OR operator
Oct 20, 2008 12:35 PM|LINK
Are you comparing strings? Can you debug to check if the isn't any errors in your variable? This should not fail.
-----------------
Please 'Mark as Answer' the post(s) that helped you
anonymouswri...
Contributor
2340 Points
424 Posts
Re: Problems with the "||" OR operator
Oct 20, 2008 12:38 PM|LINK
Can you post the complete code
Paul Linton
Star
13591 Points
2571 Posts
Re: Problems with the "||" OR operator
Oct 20, 2008 09:49 PM|LINK
Put a breakpoint on the "if ((mystring ..." line and when/if the code stops there hover over the mystring variable to see what its value is.
computers_do...
Member
485 Points
211 Posts
Re: Problems with the "||" OR operator
Oct 21, 2008 05:21 PM|LINK
Post your code and let's have a looksee! [:D]
rjcox
Contributor
7064 Points
1444 Posts
Re: Problems with the "||" OR operator
Oct 22, 2008 09:46 AM|LINK
There is no logical or that does not short circuit in C# (VB does have both, with "or" being non-short-circuiting).
As noted by another poster, need to see complete code.
shaan
Member
239 Points
50 Posts
Re: Problems with the "||" OR operator
Oct 24, 2008 09:27 AM|LINK
Might be the string you are passing is not == to "aa" or "bb"....
might be some space or some different string is coming to the variable....
other wise the if statement is write, it will come inside only if the string is "aa" or "bb"....
Shaan
radamanthys
Member
228 Points
74 Posts
Re: Problems with the "||" OR operator
Nov 06, 2008 05:17 PM|LINK
In fact, I don't recommend you use the operator "==" beacuse it compares the strings values, but in some cases it will be fails. Why don't use the method equals?
Example:
Instead of:
if((mystring == "aa") || (mystring = "bb"))
{
}
You can use:
if( (mystring.Equals("aa")) || ( myString.Equals("bb"))
{
}
And overall, It would be nice if you post the complete or se segment of code when you calls this validation.
Seeya
shandyhidaya...
Participant
1296 Points
199 Posts
Re: Problems with the "||" OR operator
Nov 07, 2008 02:04 AM|LINK
That's right, you should only use equal not '==' to Compare String Data Type
It will work, believe me.
Regards,
Shandy Hidayat
string comparison
Shandy Hidayat, MCPD
Sagar Nishan...
Participant
942 Points
152 Posts
Re: Problems with the "||" OR operator
Nov 16, 2008 04:46 PM|LINK
HI,
Your code looks fine. The problem seems to be with the string you are passing, means its not "aa" or "bb".
Nishant Sagar