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

后端 未结 6 898
孤城傲影
孤城傲影 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:20

    A single & is "Bitwise AND operator", just like dove said. I'm looking at second part of question: "why it works?"

    Think in binary:

     000 = 0
     001 = 1
     010 = 2
     011 = 3
     100 = 4
     101 = 5
     110 = 6
     111 = 7
     and so on
    

    Note all even numbers ends with 0; so if last bit bitwise check against 1 returns zero (meaning "doesn't match"), its a even number;

提交回复
热议问题