Ramon Smits

Tell me your secrets and i'll tell you mine

Recent Posts

Tags

Community

Email Notifications

Patterns & Practices / Guidelines

EntLib

Nant

Blogs that I monitor

Archives

The && and the & operators

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.

Leave a Comment

(required) 

(required) 

(optional)

(required) 


Please add 5 and 2 and type the answer here: