|
ms
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
If statement with multiple conditionC# 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 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: Show quoteHide quote >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 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. Show quoteHide quote "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 > > 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. -- Show quoteHide quote- Nicholas Paldino [.NET/C# MVP] - mvp@spam.guard.caspershouse.com "Alpha" <Al***@discussions.microsoft.com> wrote in message news:0DBC7AA0-33C2-4D13-A0D5-F7BF3A8D9DBE@microsoft.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 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) Show quoteHide quote "Alpha" <Al***@discussions.microsoft.com> wrote in message news:0DBC7AA0-33C2-4D13-A0D5-F7BF3A8D9DBE@microsoft.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 "Alpha" <Al***@discussions.microsoft.com> wrote in message In addition to the other answer, make sure you watch out for the common news:0DBC7AA0-33C2-4D13-A0D5-F7BF3A8D9DBE@microsoft.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)); mistake - almost surely you meant to write if ((radioAllItems.Checked == true) not if ((radioAllItem.Checked = true) "Jeff Connelly" <nom***@thank.you> a écrit dans le message de news: emWFRuUOFHA.3***@TK2MSFTNGP10.phx.gbl...> if ((radioAllItems.Checked == true) or even :if ((radioAllItems.Checked) ... Joanna -- Joanna Carter Consultant Software Engineer Yes, thank you. That's slick.
Show quoteHide quote "Joanna Carter (TeamB)" wrote: > "Jeff Connelly" <nom***@thank.you> a écrit dans le message de news: > emWFRuUOFHA.3***@TK2MSFTNGP10.phx.gbl... > > > if ((radioAllItems.Checked == true) > > or even : > > if ((radioAllItems.Checked) ... > > Joanna > > -- > Joanna Carter > Consultant Software Engineer > > > "Joanna Carter (TeamB)" <joannac@nospamforme.com> wrote in message Yes, if the thing you're testing is actually a boolean value, that's better.news:OAsQY4UOFHA.3156@TK2MSFTNGP15.phx.gbl... > "Jeff Connelly" <nom***@thank.you> a écrit dans le message de news: > emWFRuUOFHA.3***@TK2MSFTNGP10.phx.gbl... > >> if ((radioAllItems.Checked == true) > > or even : > > if ((radioAllItems.Checked) ... Yes, got that one when I compiled. Thanks.
Show quoteHide quote "Jeff Connelly" wrote: > > "Alpha" <Al***@discussions.microsoft.com> wrote in message > news:0DBC7AA0-33C2-4D13-A0D5-F7BF3A8D9DBE@microsoft.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) > > >
Other interesting topics
Break out of Try
include build time in exe file C# Reflection - Nasty bug?? xpath in c# Control-click deployment of dot net desktop project with crystal reports Start and exit applcation(s) using Windows Services HELP Problem serializing a structure Splitting a string array to seperate variables Retrieving HTTP Response Code |
|||||||||||||||||||||||