Re: Complex if statement.

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Mike Schilling <ap@xxxxxxxxxxxxxxxx> wrote:

"Nicholas Paldino [.NET/C# MVP]" <mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
message news:ufG4U2ChGHA.3956@xxxxxxxxxxxxxxxxxxxxxxx
Arne,

No, in C#, logical expressions short circuit themselves if it can not
effect the result.

To be precise, the operators && and || short-circuit. The operators & and
|, which can also be used in logical expressions [1], do not.

1. Note that this is different from C, C++, and Java, in which & and | are
bitwise operators only.

Not sure where you get that idea about Java from:

public class Test
{
public static void main(String[] args)
{
boolean a = true;
boolean b = false;

System.out.println (a&b);
}
}

--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
.



Relevant Pages

  • Re: Complex if statement.
    ... No, in C#, logical expressions short circuit themselves if it can ... Not sure where you get that idea about Java from: ... boolean b = false; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Coding Horrors, Cargo Cult Programming, and other Ghoulish Things
    ... a boolean, so why should I add a relation to get another boolean [my ... Where C syntax requires parentheses around logical expressions, Pascal syntax doesn't allow for anything but a logical expression for a condition. ... If this difference is not hardwired in the head of an coder, he should stick to a single language, IMO. ...
    (borland.public.delphi.non-technical)
  • Re: String concatenation design
    ... logical expressions because the results of those are ... I gave the relevant string operators a very high precedence because ... boolean + numeric could go to boolean or be disallowed IMO. ...
    (comp.programming)