简体   繁体   中英

C# & operator problem

How do I use the & binary operator correctly? randomSize is ushort.

           if (randomSize & 0x1000)
           {

           }

Error 5 Cannot implicitly convert type 'int' to 'bool'

Thanks.

The if statement expects a bool value, not just some non-zero value like in C/C++. If you are checking flags, try something like this:

if ((randomSize & 0x1000) == 0x1000)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM