Click here to Skip to main content
15,887,214 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
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 
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 
The && operator should be used instead of the & operator for clarity's sake because its the standard way of doing things. Also the && operator gives you some type safety that the & operator does not when dealing with LOGICAL ANDS: (4 && 5) will not compile but (4 & 5) will. If you are intending to perform a LOGICAL AND operation you could end up performing a LOGICAL BITWISE AND operation instead by mistake.

But in any case, the reason you are giving:

"(...)In C#, logical operators always short-circuit(...)

is so wrong I dont even know where to begin.

The operator & is an overloadable operator. Integral and boolean types have their own predefined & binary operators: &(int, int) computes the logical bitwise AND of its operands while &(bool, bool) computes the logical AND of its operands; that is, the result is true if and only if both its operands are true.

This is all straight from the C# specifications:http://msdn.microsoft.com/en-us/library/sbf85k1c.aspx[^]

So bool & bool is NOT A BITWISE OPERATION at all. Its a normal LOGICAL AND OPERATION where both terms are always evaluated contrary to bool && bool where the second term is evaluated if and only if the first term is true.
modified on Thursday, May 19, 2011 5:55 AM

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 Pin
_Erik_20-May-11 4:09
_Erik_20-May-11 4:09 
GeneralRe: Logic Pin
OriginalGriff20-May-11 4:22
mveOriginalGriff20-May-11 4:22 
GeneralRe: Logic Pin
Nathan D Cook20-May-11 4:10
Nathan D Cook20-May-11 4:10 
GeneralRe: Logic Pin
OriginalGriff20-May-11 4:21
mveOriginalGriff20-May-11 4:21 
GeneralRe: Logic Pin
Manfred Rudolf Bihy20-May-11 4:38
professionalManfred Rudolf Bihy20-May-11 4:38 
GeneralRe: Logic Pin
OriginalGriff20-May-11 4:43
mveOriginalGriff20-May-11 4:43 

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.