2

I am having a hard time porting this part of C++ to C#. I keep getting Operator '||' cannot be applied to operands of type 'long' and 'long' which makes sense. So what would the equivalent be?

    while ((c <= combinations) && ((round_set & (1 << cList[c].one)) || (round_set & (1 << cList[c].two)) || (cUsed[c])))
                   {
                   fprintf( stdout, "C: %d\n", c);
                    c++;
                    }

while ((c <= combinations) && ((round_set & (1 << cList[c].one)) || (round_set & (1 << cList[c].two)) || (cUsed[c])))
                            {
                                Console.WriteLine("C: {0}", c);

                                c++;
                            }

1 Answer 1

6

C++, unlike C#, lets you treat an integer value as if it were a boolean value, ad-hoc, where any integer 0 is false, and any integer other than 0 is true. C# does not allow this.

To achieve the same effect in C# you must explicitely perform the check I just described, so instead of

if( (expr) || ... ) { }

you want

if( (expr) != 0 || ... ) { }

And in fact the latter is still perfectly acceptable (and sometimes encouraged for clarity) in C++.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.