473,397 Members | 2,056 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

If statement with multiple condition

C# doesn't allow multiple condition in a single if ? Or did I make a mistake
with my syntax? It keep giving me syntax error when I put "and" or "or" in
the if statemnt for multiple condition checking.

if ((radioAllItems.Checked = TRUE) and
(this.lstSelections.SelectedItems.Count < lstSelections.Items.Count));

Thanks,
Alpha
Nov 17 '05 #1
9 65716
In C#, you use && for and, and || for or. Also != is not equal to.

Marcie

On Mon, 4 Apr 2005 12:01:02 -0700, "Alpha"
<Al***@discussions.microsoft.com> wrote:
C# doesn't allow multiple condition in a single if ? Or did I make a mistake
with my syntax? It keep giving me syntax error when I put "and" or "or" in
the if statemnt for multiple condition checking.

if ((radioAllItems.Checked = TRUE) and
(this.lstSelections.SelectedItems.Count < lstSelections.Items.Count));

Thanks,
Alpha


Nov 17 '05 #2
Alpha,

C# uses a different syntax for logical expressions. For and you want to
use &&, for or, you want to use ||, like so:

if ((radioAllItems.Checked = TRUE) &&
(this.lstSelections.SelectedItems.Count < lstSelections.Items.Count))

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Alpha" <Al***@discussions.microsoft.com> wrote in message
news:0D**********************************@microsof t.com...
C# doesn't allow multiple condition in a single if ? Or did I make a
mistake
with my syntax? It keep giving me syntax error when I put "and" or "or"
in
the if statemnt for multiple condition checking.

if ((radioAllItems.Checked = TRUE) and
(this.lstSelections.SelectedItems.Count < lstSelections.Items.Count));

Thanks,
Alpha

Nov 17 '05 #3
Its in the syntax:

AND = &&
OR = ||

equality: == (double equal)

if ((radioAllItems.Checked == TRUE) &&
(this.lstSelections.SelectedItems.Count < lstSelections.Items.Count))
{
// do something
}

(Also no semi-colon at the end of the if statement)

"Alpha" <Al***@discussions.microsoft.com> wrote in message
news:0D**********************************@microsof t.com...
C# doesn't allow multiple condition in a single if ? Or did I make a
mistake
with my syntax? It keep giving me syntax error when I put "and" or "or"
in
the if statemnt for multiple condition checking.

if ((radioAllItems.Checked = TRUE) and
(this.lstSelections.SelectedItems.Count < lstSelections.Items.Count));

Thanks,
Alpha

Nov 17 '05 #4

"Alpha" <Al***@discussions.microsoft.com> wrote in message
news:0D**********************************@microsof t.com...
C# doesn't allow multiple condition in a single if ? Or did I make a
mistake
with my syntax? It keep giving me syntax error when I put "and" or "or"
in
the if statemnt for multiple condition checking.

if ((radioAllItems.Checked = TRUE) and
(this.lstSelections.SelectedItems.Count < lstSelections.Items.Count));


In addition to the other answer, make sure you watch out for the common
mistake - almost surely you meant to write

if ((radioAllItems.Checked == true)

not

if ((radioAllItem.Checked = true)
Nov 17 '05 #5
Oops! Sorry for such a stupid question. And thanks to all for your help.
The operators are the same as C. I got it. Thanks again.

"Marcie Jones" wrote:
In C#, you use && for and, and || for or. Also != is not equal to.

Marcie

On Mon, 4 Apr 2005 12:01:02 -0700, "Alpha"
<Al***@discussions.microsoft.com> wrote:
C# doesn't allow multiple condition in a single if ? Or did I make a mistake
with my syntax? It keep giving me syntax error when I put "and" or "or" in
the if statemnt for multiple condition checking.

if ((radioAllItems.Checked = TRUE) and
(this.lstSelections.SelectedItems.Count < lstSelections.Items.Count));

Thanks,
Alpha


Nov 17 '05 #6
"Jeff Connelly" <no****@thank.you> a écrit dans le message de news:
em**************@TK2MSFTNGP10.phx.gbl...
if ((radioAllItems.Checked == true)


or even :

if ((radioAllItems.Checked) ...

Joanna

--
Joanna Carter
Consultant Software Engineer
Nov 17 '05 #7
Yes, got that one when I compiled. Thanks.

"Jeff Connelly" wrote:

"Alpha" <Al***@discussions.microsoft.com> wrote in message
news:0D**********************************@microsof t.com...
C# doesn't allow multiple condition in a single if ? Or did I make a
mistake
with my syntax? It keep giving me syntax error when I put "and" or "or"
in
the if statemnt for multiple condition checking.

if ((radioAllItems.Checked = TRUE) and
(this.lstSelections.SelectedItems.Count < lstSelections.Items.Count));


In addition to the other answer, make sure you watch out for the common
mistake - almost surely you meant to write

if ((radioAllItems.Checked == true)

not

if ((radioAllItem.Checked = true)

Nov 17 '05 #8
Yes, thank you. That's slick.

"Joanna Carter (TeamB)" wrote:
"Jeff Connelly" <no****@thank.you> a écrit dans le message de news:
em**************@TK2MSFTNGP10.phx.gbl...
if ((radioAllItems.Checked == true)


or even :

if ((radioAllItems.Checked) ...

Joanna

--
Joanna Carter
Consultant Software Engineer

Nov 17 '05 #9

"Joanna Carter (TeamB)" <jo*****@nospamforme.com> wrote in message
news:OA**************@TK2MSFTNGP15.phx.gbl...
"Jeff Connelly" <no****@thank.you> a écrit dans le message de news:
em**************@TK2MSFTNGP10.phx.gbl...
if ((radioAllItems.Checked == true)


or even :

if ((radioAllItems.Checked) ...


Yes, if the thing you're testing is actually a boolean value, that's better.
Nov 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: msreerajan | last post by:
I'm having an Employee table with a Salary field. How can we increate the salary of the employees with following conditions: 1) salary between 1000 and 10000 : increase 25% 2) salary between 10000...
0
by: js | last post by:
I am using the Microsoft.Practices.EnterpriseLibrary and trying to bind all the DropDownList controls on a page by calling the following function at Page_Load event. My attempt is make only one...
6
by: Allerdyce.John | last post by:
Hi, How can I put multiple condition in if statement? I try this, but I can't get that to work. if ( (str != " ") && (str != "") ): Any help is appreciated.
7
by: apattin | last post by:
Hi experts, I am having a hard time coding a trigger to handle multiple validation conditions in DB2 UDB V8.1.9.. I thought that a single trigger might be better than one-trigger-per-condition,...
2
by: Mersilla | last post by:
Dear All, I am currently new to perl and is experiencing difficulties with splitting and array with multiple conditions. For example , I would like to spilt an element, which contains one or...
2
by: fran7 | last post by:
Hi, I have this IF statement <% If rsCard("DefaultMessage")="e-card" Then %> <a href="cards.asp?Post=<%=rsCard("Post")%>"> <% Else
16
by: Johannes Bauer | last post by:
Hello group, I'm just starting with Python and am extremely unexperienced with it so far. Having a strong C/C++ background, I wish to do something like if (q = getchar()) { printf("%d\n", q);...
3
by: HowHow | last post by:
I am using Excel 2000 to calculate the pay for worker and there are 4 possibility: 1.If actual work time is within 5 minutes under rostered time, pay rostered time 2.If actual work time is 5...
0
by: crwill | last post by:
I need help with a multiple condition trigger. I saw a post on Dec '06 and coded my trigger like that one but it still doesn't work. I am using DB2 V9 on z/OS. CREATE TRIGGER DB2DBA.DSOPTCR5 ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.