By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,028 Members | 1,784 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,028 IT Pros & Developers. It's quick & easy.

If statement with multiple condition

P: n/a
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
Share this Question
Share on Google+
9 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a

"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

P: n/a
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

P: n/a
"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

P: n/a
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

P: n/a
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

P: n/a

"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 discussion thread is closed

Replies have been disabled for this discussion.