How to use the & operator in C#? Is the the translation of the code correct?

前端 未结 3 368
时光说笑
时光说笑 2021-01-20 15:31

the line \"if(arg2 & 1)\" in C++(arg2 is DWORD) is equal to \"if(arg2 & 1==0)\" in C#(arg2 is Uint32),right?

I am trying to translate a function from C++ to

3条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-20 15:41

    1. DWORD is uint32_t in C++, thus UInt32 in C#.
    2. if(a & b) converts to if((a & b) != 0). != is evaluated before & thus the & expression needs parentheses around it.
    3. if(x) converts to if(x != 0)
    4. & is a 'bitwise and' in C#, like in C++.
    5. Depends on your C++ structure.

提交回复
热议问题