here is a tl;dr
I come from a C++ background. && is suppose to check if left side is true and right side is true. what does & have anything to do with this? Why is it being used in the && logic?
I couldnt understand http://msdn.microsoft.com/en-us/library/aa691312%28v=vs.71%29.aspx and asked a question. It took me quite a while to understand and accept this answer. I had to do a lot of follow up reading How does operator overloading of true and false work?
The operation x && y is evaluated as T.false(x) ? x : T.&(x, y)
Why on earth is it doing this? if the false overload returns true and the true operator returns true then y is not evaluated at all. WTF!!!!
I still cant understand it. Because of this being so weird to me it took me a while to understand the answers in the other question. In C# v = 1 && 2;
does not work bc you cant do && on ints. In C this returns true (heres code/example http://codepad.org/9iCaqzQ2). If we follow the operation rule above for this we would do
(using 1 && 2)
- Int.False(1) is false
- 1 & 2 (== 0)
- Int.True(0) (== false)
This would get you the wrong results.
So... What is the reasoning for C# doing the && (and ||) operator(s) the way it does.