Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8322775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:29:50+00:00 2026-06-08T23:29:50+00:00

Anyway here’s my problem I have been modifying a whole C++ program to work

  • 0

Anyway here’s my problem I have been modifying a whole C++ program to work in C# and I am pretty much done, I have this If statement in the C++ program.

if(info[i].location & 0x8 || 
             info[i].location & 0x100|| 
                     info[i].location & 0x200)
{
    //do work
}
else
{
    return
}

And of course when I do this in C# it gives me a "Operator ‘||’ cannot be applied to operands of type ‘int’ and ‘int’" error.

Any clue on what my problem is, Im guessing that C# has got a way of doing this as I am fairly unfamiliar with these old C operators.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T23:29:52+00:00Added an answer on June 8, 2026 at 11:29 pm

    Why it fails

    Fundamentally it’s the same difference as this:

    if (someInteger) // C or C++
    

    vs

    if (someInteger != 0) // C#
    

    Basically C# is a lot stricter when it comes to logical operators and conditions – it forces you to have use something which is either bool or convertible to bool.

    As an aside, that’s also why in C# this isn’t just a warning, but a full-blown error:

    int x = ...;
    if (x = 10) // Whoops - meant to be == but it's actually an assignment
    

    If you see comparisons this way round:

    if (10 == x)
    

    That’s usually developers trying to avoid typos like the above – but it’s not needed in C# unless you’re really comparing against constant bool values.

    Fixing the problem

    I suspect you just need:

    if (((info[i].location & 0x8) != 0)) ||
        ((info[i].location & 0x100) != 0)) ||
        ((info[i].location & 0x200) != 0)))
    

    It’s possible that you don’t need all of those brackets… but another alternative is just to use one test:

    if ((info[i].location & 0x308) != 0)
    

    After all, you’re just testing whether any of those three bits are set…

    You should also consider using a flags-based enum:

    [Flags]
    public enum LocationTypes
    {
        Foo = 1 << 3; // The original 0x8
        Bar = 1 << 8; // The original 0x100
        Baz = 1 << 9; // The original 0x200
    }
    

    Then you could use:

    LocationTypes mask = LocationTypes.Foo | LocationTypes.Bar | LocationTypes.Baz;
    if ((info[i].location) & mask != 0)
    

    Or using Unconstrained Melody:

    LocationTypes mask = LocationTypes.Foo | LocationTypes.Bar | LocationTypes.Baz;
    if (info[i].location.HasAny(mask))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

maybe it's not so proper to ask this question here... anyway, I'm trying to
I know this is a bit bleeding edge, but here's the question anyway: Given
I have been struggling with this issue for a few hours now without understanding
I don't know whether this is the right forum. Anyway here is the question.
I'm not sure whether to post it here or at ServerFault. Anyway, I'm trying
Just getting into SQL stored queries right now... anyway, here's my database schema (simplified
For more info, see my other question, here . So anyway, I'm using BigDecimals
This seems very basic and I must be missing something, but here goes anyways...
Well I guess this has been asked a thousand times, but for some reason
UPDATE So I am still messing with this, and have gotten as far as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.