469,619 Members | 1,867 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,619 developers. It's quick & easy.

Convert VB to C#, Operator "Or"

ano
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
Jun 22 '06 #1
5 6056
ano wrote:
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
Jun 22 '06 #2
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"ano" <an*@discussions.microsoft.com> wrote in message
news:8B**********************************@microsof t.com...
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

Jun 22 '06 #3
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
"ano" wrote:
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

Jun 22 '06 #4
Ano,
You should use | instead of ||

Unlike VB, C# has different boolean and bitwise operators.
--
HTH
Stoitcho Goutsev (100)
"ano" <an*@discussions.microsoft.com> wrote in message
news:8B**********************************@microsof t.com...
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

Jun 22 '06 #5
ano
Thanks, all!!! It's really help.

"Stoitcho Goutsev (100)" wrote:
Ano,
You should use | instead of ||

Unlike VB, C# has different boolean and bitwise operators.
--
HTH
Stoitcho Goutsev (100)
"ano" <an*@discussions.microsoft.com> wrote in message
news:8B**********************************@microsof t.com...
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


Jun 22 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Sean Dettrick | last post: by
4 posts views Thread by Bradley Plett | last post: by
2 posts views Thread by Serious_Practitioner | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.