Equivalent VB.Net code for Bitwise Inclusive OR Operator (|) in CS

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

What is the equivalent VB.net code for Bitwise Inclusive OR Operator (|) in
CSharp?

Example what is the equivalent VB.net code for the following CSharp.net code?

dwFlags = CRYPTPROTECT_LOCAL_MACHINE|CRYPTPROTECT_UI_FORBIDDEN;
 
Chrysan said:
What is the equivalent VB.net code for Bitwise Inclusive OR Operator (|) in
CSharp?

Example what is the equivalent VB.net code for the following CSharp.net code?

dwFlags = CRYPTPROTECT_LOCAL_MACHINE|CRYPTPROTECT_UI_FORBIDDEN;

dwFlags = CRYPTPROTECT_LOCAL_MACHINE Or CRYPTPROTECT_UI_FORBIDDEN

Yup, confusingly, the Or operator is for both logical and bitwise Or
operations.

Damien
 
Damien said:
dwFlags = CRYPTPROTECT_LOCAL_MACHINE Or CRYPTPROTECT_UI_FORBIDDEN

Yup, confusingly, the Or operator is for both logical and bitwise Or
operations.

Damien
This is not quite correct. Or is the bitwise operator as you say; OrElse is
the logical operator.

Regards,

Nick Hall
 
This is not quite correct. Or is the bitwise operator as you say; OrElse
is the logical operator.

No, OrElse is used for shortcurcuiting the logical evaluation. Or is also a
logical operator.
 
Both VB and C# have bitwise operators which also are used as
non-short-circuiting operators:
"Or" and "And" in VB
| and & in C#

The short-circuiting operators:
"OrElse" and "AndAlso" in VB
|| and && in C#

The corresponding logical operators in each language behave identically in
each language.

--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB.NET to C# Converter
Instant VB: C# to VB.NET Converter
Instant C++: C# to C++ Converter
Instant J#: VB.NET to J# Converter
 
Comments inline...

CT said:
No, OrElse is used for shortcurcuiting the logical evaluation. Or is also
a logical operator.

Um yes, OrElse can be used for shortcircuiting because it is a logical
operator. The || operator in C# works in exactly the same way.
Any bitwise operator can also be used as a logical operator when the
operands are boolean (after all False has all the bits switched off and True
has all the bits switched On). Or certainly HAS been used as a logical
operator in prior versions of VB since it was the only option - and it still
can. OrElse is now the more correct option to use.Nick Hall
 
OrElse is now the more correct option to use.

Nice catch, although I don't necessarily agree. ;-)
 
Back
Top