Click here to Skip to main content
15,887,373 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: Logic Pin
Liju Sankar25-May-11 3:42
Liju Sankar25-May-11 3:42 
GeneralRe: Logic Pin
agolddog25-May-11 3:51
agolddog25-May-11 3:51 
GeneralRe: Logic Pin
dchrno25-May-11 4:02
dchrno25-May-11 4:02 
GeneralRe: Logic Pin
Jason Christian25-May-11 7:13
Jason Christian25-May-11 7:13 
GeneralRe: Logic Pin
Shameel17-May-11 7:56
professionalShameel17-May-11 7:56 
GeneralRe: Logic Pin
hairy_hats25-May-11 0:59
hairy_hats25-May-11 0:59 
GeneralRe: Logic Pin
Mel Padden26-May-11 21:06
Mel Padden26-May-11 21:06 
GeneralRe: Logic Pin
Keith Barrow18-May-11 4:52
professionalKeith Barrow18-May-11 4:52 
Fabio V Silva wrote:
They do the same except for the fact that && is short-circuited.


Except they don't do they? For boolean operands they do the same thing, (ignoring, as you said, the short circuiting which is a very good reason to use &&).

Take this example:
C#
Console.WriteLine( 42 && 3);

Syntax error. Why? Because it is a Logical Operator which takes booleans as its operands.

Now take:
C#
Console.WriteLine( 42 & 3)</pre> 
Answer 2: Why? Because it is  a Bitwise Logical Operator (though most people drop the "Logical") ANDing on the bits:

101010 AND
000011
------
000010

= 2.

The bitwise <code>|</code> and <code>&</code> operators are best left for work at the bit-level (such as bit-masking), whereas the the C# logical operators are better suited to boolean comparisons, like in the OP.

I wouldn't have voted you down BTW, but I would have pointed it out.
<div class="signature"><small><a href="http://tinyurl.com/3yl74on">Sort of a cross between Lawrence of Arabia and Dilbert.</a>[<a href="http://tinyurl.com/3yl74on" target="_blank" title="New Window">^</a>]<br>-Or-<br><a href="http://tinyurl.com/36qcqfr">A Dead ringer for Kate Winslett</a>[<a href="http://tinyurl.com/36qcqfr" target="_blank" title="New Window">^</a>]</small>
</div>

GeneralRe: Logic Pin
gumi_r@msn.com17-May-11 7:08
gumi_r@msn.com17-May-11 7:08 
GeneralRe: Logic Pin
Fabio V Silva17-May-11 7:49
Fabio V Silva17-May-11 7:49 
GeneralRe: Logic Pin
Shameel17-May-11 7:52
professionalShameel17-May-11 7:52 
GeneralRe: Logic Pin
Shameel17-May-11 8:10
professionalShameel17-May-11 8:10 
GeneralRe: Logic [modified] PinPopular
gumi_r@msn.com18-May-11 23:35
gumi_r@msn.com18-May-11 23:35 
GeneralRe: Logic Pin
0bx18-May-11 21:05
0bx18-May-11 21:05 
GeneralRe: Logic PinPopular
AspDotNetDev17-May-11 11:02
protectorAspDotNetDev17-May-11 11:02 
GeneralRe: Logic Pin
Fabio V Silva17-May-11 11:30
Fabio V Silva17-May-11 11:30 
GeneralRe: Logic Pin
Quirkafleeg20-May-11 4:39
Quirkafleeg20-May-11 4:39 
GeneralRe: Logic PinPopular
_Erik_18-May-11 3:45
_Erik_18-May-11 3:45 
GeneralRe: Logic Pin
Fabio V Silva18-May-11 4:09
Fabio V Silva18-May-11 4:09 
GeneralRe: Logic Pin
_Erik_18-May-11 4:29
_Erik_18-May-11 4:29 
GeneralRe: Logic Pin
Keith Barrow18-May-11 5:03
professionalKeith Barrow18-May-11 5:03 
GeneralRe: Logic Pin
Shameel18-May-11 23:55
professionalShameel18-May-11 23:55 
GeneralRe: Logic Pin
Nagy Vilmos19-May-11 0:04
professionalNagy Vilmos19-May-11 0:04 
GeneralRe: Logic Pin
gumi_r@msn.com20-May-11 0:02
gumi_r@msn.com20-May-11 0:02 
GeneralRe: Logic PinPopular
_Erik_20-May-11 4:09
_Erik_20-May-11 4:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.