Search code examples
c#monodevelopxamarin-studio

C# Suggestion Convert to '|=' expression


Okay, I apologize if this is a stupid question but I can't get a google search to find what I'm looking for and I'm not sure where else to turn. I was writing some C# code and have a simple if statement looking at 2 booleans.

if(a && !b)
    do something

I'm using MonoDevelop or Xamarin Studio or whatever it's called and it underlined the if in blue and the popup says: Suggestion: Convert to '|=' expression. I'm not an inexperienced programmer but I don't think I've ever seen |= before and I have no idea what that means or what this suggestion is suggesting, if it's actually even valid at all. Anyone willing to clue me in? Thanks for any help.

Editing in some more because others asked The real code is not much more than that. It's essentially

if(a && !b)
    c = true;

Not quite sure how I could make the bitwise shortcut operator work here since I'm using three different variables, but bitwise operations are a huge lacking point of my abilities. But that is exactly what the suggestion is saying on the underlined if.


Solution

  • It's a bitwise OR and assignment. a |= b is equivalent to a = a | b.