GrzesiekO
GrzesiekO

Reputation: 1199

Question about |= in c#

What means |= in c#?

Example:

int a= 0;
int b = a |= 5;

I can't find any hints for this.

Upvotes: 4

Views: 523

Answers (6)

Jarrett Phillips
Jarrett Phillips

Reputation: 133

This is in the MSDN Library under operators for c#

http://msdn.microsoft.com/en-us/library/h5f1zzaw.aspx

Upvotes: 3

Vladimir
Vladimir

Reputation: 3689

Bitwise or.

Your snippet becomes.

int a = 0;
int b;
a = a | 5;
b = a;

In the end, a = b = 5

Upvotes: 2

Peter Kelly
Peter Kelly

Reputation: 14391

It is an assignment operator that performs a bitwise logical OR on integral operands and a logical OR on bool operands.

http://msdn.microsoft.com/en-us/library/h5f1zzaw(v=VS.100).aspx

Upvotes: 2

Dylan Meador
Dylan Meador

Reputation: 2401

"|" is a bitwise OR operator. http://msdn.microsoft.com/en-us/library/kxszd0kx(v=vs.71).aspx

So,

a |= 5;

is the same as

a = a | 5;

Upvotes: 4

Daniel Walker
Daniel Walker

Reputation: 770

|= is the OR assignment operator.

http://msdn.microsoft.com/en-us/library/h5f1zzaw.aspx

Upvotes: 4

Luis Valencia
Luis Valencia

Reputation: 33998

the OR assignment operator.

full explanation is here. http://msdn.microsoft.com/en-us/library/h5f1zzaw(v=vs.71).aspx

Upvotes: 12

Related Questions