.NETGURU
Difference in && and &=
Messages   Related Types
This message was discovered on microsoft.public.dotnet.languages.csharp.

Post a new message to this list...

Joel
Run this method:

public void test()
{
bool b;
int i=0;

b=false;
i=0;
b=(b && i++==1);
Console.WriteLine(i.ToString());

b=false;
i=0;
b&=i++==1;
Console.WriteLine(i.ToString());
}

Notice how in the first syntax, i++ is NOT evaluated (because of
short-circuit evaluation) but in the second syntax i++ is evaluated. I
wonder if this was intentional or an oversight. It burned me in a situation
when I was counting on short-circuit evaluation.

<joel>

Reply to this message...
 
    
Chris R. Timmons
"Joel" <Click here to reveal e-mail address> wrote in
news:eIfF$Click here to reveal e-mail address:

[Original message clipped]

Joel,

& and && are two completely different operators. & performs a
bitwise "and" of two numbers, but && is the boolean "and" operator.
Change the && to & and both code blocks return the same result (1).

--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Reply to this message...
 
    
Xarky
"Chris R. Timmons" <Click here to reveal e-mail address> wrote in message news:<Xns95639CAC22BA5crtimmonscrtimmonsin@207.46.248.16>...
[Original message clipped]

Is short-circuit evaluation the same as lazy evaluation?
Reply to this message...
 
    
Chris R. Timmons
Click here to reveal e-mail address (Xarky) wrote in
news:Click here to reveal e-mail address:

[Original message clipped]

http://en.wikipedia.org/wiki/Lazy_evaluation

and

http://en.wikipedia.org/wiki/Short_circuit

--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Reply to this message...
 
    
Joel
Yeah, I'm aware of the difference between & and && (and and and? ;-). Just
pointing out a 'gotcha' that 'gotme'.

</joel>

"Chris R. Timmons" <Click here to reveal e-mail address> wrote in message
news:Xns95648D90EBDEFcrtimmonscrtimmonsin@207.46.248.16...
[Original message clipped]

Reply to this message...
 
 
System.Console




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification