Convert VB to C#, Operator "Or"

G

Guest

Hi,

I have converted this VB code to C# but I got this error:
"Operator '||' cannot be applied to operands of type 'int' and 'short'"

Is VB allow to use Operator "Or" with 'int'?
If yes, how to do this in c#?

Thanks,

VB:

Private Const SERVICE_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or
SERVICE_QUERY_CONFIG Or SERVICE_CHANGE_CONFIG Or SERVICE_QUERY_STATUS Or
SERVICE_ENUMERATE_DEPENDENTS Or SERVICE_START Or SERVICE_STOP Or
SERVICE_PAUSE_CONTINUE Or SERVICE_INTERROGATE Or SERVICE_USER_DEFINED_CONTROL)

Private Const STANDARD_RIGHTS_REQUIRED = &HF0000
Private Const SC_MANAGER_CONNECT = &H1
Private Const SC_MANAGER_CREATE_SERVICE = &H2
Private Const SC_MANAGER_ENUMERATE_SERVICE = &H4
Private Const SC_MANAGER_LOCK = &H8
Private Const SC_MANAGER_QUERY_LOCK_STATUS = &H10
Private Const SC_MANAGER_MODIFY_BOOT_CONFIG = &H20


C#

private const int SERVICE_ALL_ACCESS = ( STANDARD_RIGHTS_REQUIRED ||
SERVICE_QUERY_CONFIG ||
SERVICE_CHANGE_CONFIG ||
SERVICE_QUERY_STATUS ||

SERVICE_ENUMERATE_DEPENDENTS ||
SERVICE_START ||
SERVICE_STOP ||
SERVICE_PAUSE_CONTINUE ||
SERVICE_INTERROGATE ||

SERVICE_USER_DEFINED_CONTROL );

Private Const STANDARD_RIGHTS_REQUIRED = 0xF0000
Private Const SC_MANAGER_CONNECT = 0x1
Private Const SC_MANAGER_CREATE_SERVICE = 0x2
Private Const SC_MANAGER_ENUMERATE_SERVICE = 0x4
Private Const SC_MANAGER_LOCK = 0x8
Private Const SC_MANAGER_QUERY_LOCK_STATUS = 0x10
Private Const SC_MANAGER_MODIFY_BOOT_CONFIG = 0x20
 
T

Tom Spink

ano said:
Hi,

I have converted this VB code to C# but I got this error:
"Operator '||' cannot be applied to operands of type 'int' and 'short'"

Is VB allow to use Operator "Or" with 'int'?
If yes, how to do this in c#?

Thanks,
<snippedy-doo-dah>

Hi Ano,

You're using the logical or operator, as opposed to the bitwise or operator.
Double-pipe is logical, single-pipe is bitwise. Change your || to |, and
try that.

-- Tom Spink
 
N

Nicholas Paldino [.NET/C# MVP]

Ano,

|| is the logical operator in C#. Or is a combination of logical and
bitwise operator in VB.

In C#, you want to use |, not ||.

Hope this helps.
 
G

Guest

The C# equivalent to "Or" is "|" (single pipe).
The C# equivalent to "And" is "&" (single ampersand).

"|" and "&" are the bitwise operators (and non-short-circuit logical
operators) in C#.

It's only "OrElse" that converts to "||" and "AndAlso" that converts to "&&".
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter
Instant C++: VB to C++ converter
 
S

Stoitcho Goutsev \(100\)

Ano,


You should use | instead of ||

Unlike VB, C# has different boolean and bitwise operators.
 
G

Guest

Thanks, all!!! It's really help.

Stoitcho Goutsev (100) said:
Ano,


You should use | instead of ||

Unlike VB, C# has different boolean and bitwise operators.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top