What is the second meaning of a single ampersand in C#?

后端 未结 6 880
孤城傲影
孤城傲影 2021-02-14 03:52

I have used the single ampersand (&) in C# to mean \"check the second conditional statement even if the first is false\".

But the

6条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-14 04:14

    For boolean types, what you mentioned is how it behaves.

    For integer types, it's the bitwise "and" operator.

    It can be overloaded for other types.

    Basically, the expression (i & 1) == 0 checks to see whether the least significant bit of i is set, which only happens if the number is odd.

提交回复
热议问题