For example, if I write Console.WriteLine(1<<2<<2+1);
in C# console application, the output will be 32
Can you say me why? What does this "<<" operator mean? Where can I read more about it? I google but couldn't find it
For example, if I write Console.WriteLine(1<<2<<2+1);
in C# console application, the output will be 32
Can you say me why? What does this "<<" operator mean? Where can I read more about it? I google but couldn't find it
From MSDN:
The left-shift operator (<<) shifts its first operand left by the number of bits specified by its second operand. The type of the second operand must be an int or a type that has a predefined implicit numeric conversion to int.
https://msdn.microsoft.com/en-us/library/a1sway8w.aspx
The number 32 is returned in this case because the addition operator has precedence over the ASHL (<<) operator, but the leftmost ASHL operators are applied first. The expression is evaluated as follows:
1<<2<<2+1
((1<<2)<<(2+1))
((1<<2)<<3)
(4<<3)
32