The && and the & operators

Published 29 August 6 2:27 PM | Ramon Smits

Today a collegue had me flabbergasted by using the & operator in a boolean comparison like the following example.

return x & y;

Both x and y were booleans and I said "Hey you just forgot an &! A single & is a bitwise operator.". And he responded that this would work but that the behaviour of a single & is that it is not lazy evaluated (short-circuiting).

My knowledge about the csharp language is quite good as is my knowledge of the .net framework so this was quite a surprise!

The funny thing is that the msdn documentation about the & operator doesn't say anything about lazy evaluation while the documentation about the && operator also mentiones the & operator with boolean operands.

Filed under: , ,