tags:

views:

117

answers:

5

What is the equivalent of the |= operator in Visual Basic? For example (C#):

flags |= MyEnum.SomeFlag

+5  A: 

flags = flags Or MyEnum.SomeFlag

Gabe
So you've got to use the long way? There's no operator like `Or=` or anything? :(
Jake Petroules
No there is not. See the link I posted for more details in MSDN.
Rodney Foley
@Jake Petroules a 'ByRef' function? ;-)
pst
Jake: Only the symbol (non-English-words) operators get the compound assignment variant. And even then, I believe those operators are fairly recent.
Gabe
A: 

flags = flags Or MyEnum.SomeFlag

http://msdn.microsoft.com/en-us/library/wz3k228a(VS.80).aspx

Rodney Foley
A: 

Not that this is any sort of official source, but check out these pages:

It seems to me that there isn't an existing combination of the bitwise-or-plus-assignment operator in VB.NET. But there is a bitwise-or operator, and an assignment operator, which you can combine manually:

flags = flags Or MyEnum.SomeFlag
Merlyn Morgan-Graham
Gabe
@Gabe: Good info. I don't program in that language, I just use google ;) Will remove it from my answer
Merlyn Morgan-Graham
+1  A: 

In C#, |= is the Or assignment operator.

There's no equivalent operator in VB.

See the list of Assignment Operators (Visual Basic).

Leniel Macaferi
+1  A: 

Visual Basic does not support compound assignment operators as shown in the C# sample. You'll need to use the expanded form of the assignment and the vb version of the bitwise or operator (simple Or)

flags = flags Or MyEnum.SomeFlag
JaredPar