Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

c# syntax for OR Clause

Status
Not open for further replies.

LauraCairns

Programmer
Joined
Jul 26, 2004
Messages
173
Location
GB
Can someone please tell me what the correct syntax is for an if statement with an or clause.

Id like to be able to do the following.

if(int.Parse(No1.Text) OR int.Parse(No2.Text) OR int.Parse(No3.Text) OR int.Parse(No4.Text) OR int.Parse(No5.Text) == int.Parse(TotalPages.Text))
{
NextPage.Enabled = false;
Next5.Enabled = false;
LastPage.Enabled = false;
}
 
use two vertical lines as or, ie ||
 
Actually, in this case you only want one vertical line, see below:

if(int.Parse(No1.Text) | int.Parse(No2.Text) | int.Parse(No3.Text) | int.Parse(No4.Text) | int.Parse(No5.Text) == int.Parse(TotalPages.Text))
{
NextPage.Enabled = false;
Next5.Enabled = false;
LastPage.Enabled = false;
}
 
Actually, can you explain exactly what you are trying to achieve in that example?
 
LauraCairns -

This bit of code:
Code:
int.Parse(No1.Text)
will return an int, not a boolean. In order to cleanly use it in an "if" statement, you'll need to do a comparison of some kind, probably against 0 in this case:
Code:
(int.Parse(No1.Text) != 0)
Chip H.



____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
The code has already got a comparison operator, in bold below

if(int.Parse(No1.Text) | int.Parse(No2.Text) | int.Parse(No3.Text) | int.Parse(No4.Text) | int.Parse(No5.Text) == int.Parse(TotalPages.Text))

What this code should do is check to see if the integer values in No1 - No5 are the same, and if so compare them to the integer value in TotalPages. Although I would be inclined to put brackets around the left hand side of the == to make this explicit.

Is this the behaviour you are after?
 
Ignore me, I am talking crap!
 
The full if statement (if that's what you intend) would be:
Code:
if ((int.Parse(No1.Text) != 0) || 
    (int.Parse(No2.Text) != 0) || 
    (int.Parse(No3.Text) != 0) ||
    (int.Parse(No4.Text) != 0) ||
    (int.Parse(No5.Text) == int.Parse(TotalPages.Text)))
Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top