0

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.

cardician
  • 2,451
  • 3
  • 26
  • 36
  • 1
    [SymbolHound is your friend](http://symbolhound.com/?q=what+is+|%3D) – default Feb 12 '15 at 17:23
  • 3
    I’m having a hard time believing this. Can you post the whole `if`, including the `do something` part? – Konrad Rudolph Feb 12 '15 at 17:24
  • SymbolHound? Thanks. Hadn't heard of it but looks like it will be very helpful. – cardician Feb 12 '15 at 17:25
  • It is like += or -=. – Thorsten Dittmar Feb 12 '15 at 17:26
  • if your only question is "what is this" it should be closed as a duplicate for instance to [this](http://stackoverflow.com/questions/5492747/what-is-the-operator-how-can-i-implement-this-in-c) or [this](http://stackoverflow.com/questions/7041028/question-about-in-c-sharp) or [this](http://stackoverflow.com/questions/6942477/what-does-single-pipe-equal-and-single-ampersand-equal-mean-in-c-sharp). If your question is about why you get a suggestion to convert it, it might need some editing to highlight this. – default Feb 12 '15 at 17:28
  • That's fine, it can be closed. I can't seem to turn up anything when searching on |= though so would love to know how others are doing that. – cardician Feb 12 '15 at 17:29
  • 1
    well, I did give you the symbolhound suggestion :) however, I still think there are people here who are wondering why you got that suggestion (including me). It might be a valid question if you add details regarding what it wanted to convert. – default Feb 12 '15 at 17:31
  • Thanks for the edit. What does performing the conversion convert it into? – itsme86 Feb 12 '15 at 17:36
  • I'm not able to. Monodevelop just shows it as a text bubble when I highlight the underline. It's not actually providing me the ability to change the code for me as far as I can tell. – cardician Feb 12 '15 at 17:38

2 Answers2

3

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

itsme86
  • 19,266
  • 4
  • 41
  • 57
  • 1
    this is only answering part of the question - OP is also asking why he gets a suggestion to convert the existing expression. – default Feb 12 '15 at 17:24
  • 1
    @Default That would require more detail about the exact statement used. – itsme86 Feb 12 '15 at 17:26
  • No, that's what I was asking. And of course, I don't know why I didn't think of bitwise operators. I deal so rarely with them that I just never think about them. Stupid question, as I said. Thanks very much for the help. I'll mark your answer as accepted when it lets me in 10 minutes. Though perhaps a mod will prefer to just delete this. – cardician Feb 12 '15 at 17:27
0

You can look at code that handles this case for more details.

MonoDevelop(and almost all Xamarin Studio(except mobile AddIns)) is open source.

https://github.com/icsharpcode/NRefactory/blob/master/ICSharpCode.NRefactory.CSharp.Refactoring/CodeIssues/Synced/PracticesAndImprovements/ConvertIfToOrExpressionIssue.cs

David Karlaš
  • 942
  • 2
  • 6
  • 11