cpp to c# - & operator

Hi, I am rewriting my cpp app to c# and I am unable to convert this part:

int flags = object.Flags;
if (flags & 1)
{
...
}
if (flags & 2)
{
...
}

I am getting this error: 'Cannot implicitly convert type 'int' to 'bool''
Thx for help.



Answer this question

cpp to c# - & operator

  • Vampire7639

    thats right, so what are you trying to do here are you able to explain a bit more on the logic

  • Osiris43

    Code I posted works in cpp. However it gives error in c# so I need to know how it should be written in c#. Hope you understand me now, thx.
  • franziss

    You are performing Bitwise & on 2 integer numbers which will result in another interger while If(....) statement excepts a bool value instead so you ar getting this error. Can you post that portion of C++ code may be you are doing some mistake in conversion so we can think and solve it.

    Best Regards,

    Rizwan aka RizwanSharp



  • Francesco De Vittori

    Tibor: Thats it, thx!
  • Dreedle

    Hi,

    i had the same problem, while i am migrate from c/c++ to c# for a long time... The problem is that in c# the if-"Courier New, Courier, Monospace" color=#0000ff>int flags = object.Flags;
    if ( (flags & 1) != 0)
    {
    ...
    }
    if ( (flags & 2) != 0)
    {
    ...
    }



  • cpp to c# - & operator