super sahar
super sahar

Reputation: 425

operator '<<' cannot be applied to operands of type 'bool' and 'int'

Here is part of my code

ushort code = ...;
...
code <<= 1;
code |=  (NextBit(ref isEndOfScan) << 0); //ERROR

bool NextBit(ref bool isEndOfScan) returning bool

I am rewriting my code from c++ to c#. I've tried to convert function result to int or write false instead of 0, but nothing helped.
I want to set 0 bit of variable code.

Upvotes: 0

Views: 123

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1500873

C++ allows some conversions that C# doesn't - particularly around Boolean values.

In this case, you can just use the conditional operator to treat the return value as 1 or 0:

code |= NextBit(ref isEndOfScan) ? 1 : 0;

Upvotes: 4

Related Questions