Reputation: 475
I could see this operator |= used in some sample code in my project. The exact code is given below
DocumentRetrievalOptions docRetrievalOptions = DocumentRetrievalOptions.ByTargetJurisdiction;
docRetrievalOptions |= DocumentRetrievalOptions.ByUniqueId;
Where 'DocumentRetrievalOptions' is of type enum.
It would be of great help, if some one lets me know, what really does this mean.
Upvotes: 3
Views: 449
Reputation: 2181
Also read this: http://msdn.microsoft.com/en-us/library/system.flagsattribute.aspx It's really usefull if you wish to use this operator in this way.
Upvotes: 1
Reputation: 23268
Usually values in an enumeration are used as flags, the |= or "or equals" operator simply takes the bit representation of these values and does a bitwise OR on them. This way you "enable" another feature or flag of the enumeration (in this case the retrieval options for a document os its either by target jursisdiction OR unique id).
Upvotes: 1
Reputation: 324630
It is a shortcut for:
docRetrievalOptions = docRetrievalOptions | DocumentRetrievalOptions.ByUniqueId;
|
being the bitwise-OR operator. In this way it works similarly to +=
, -=
and other operators in this style.
Upvotes: 1
Reputation: 7480
It applies the * bitwise or* operator (|
) to both operands and stores the result inside docRetrievalOptions
.
It is the same as docRetrievalOptions = docRetievalOptions | DocumentRetrievalOptions.ByUniqueId;
It interprets the enumeration as an int and then does the operation.
Upvotes: 0
Reputation: 726569
It is a Bitwise/Logical OR - assign operator. A |= B;
is the same as A = A | B;
Since DocumentRetrievalOptions
is an enum
, in your case |=
performs a bitwise operation.
Upvotes: 6