The && and the & operators

By ramon
August 29, 2006
0

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.

Comments: 0

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Recent Posts
  • Recent Comments
  • Archives
  • Categories
  • Meta