PC Review


Reply
Thread Tools Rate Thread

Convert VB to C#, Operator "Or"

 
 
=?Utf-8?B?YW5v?=
Guest
Posts: n/a
 
      22nd Jun 2006
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
 
Reply With Quote
 
 
 
 
Tom Spink
Guest
Posts: n/a
 
      22nd Jun 2006
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
 
Reply With Quote
 
Nicholas Paldino [.NET/C# MVP]
Guest
Posts: n/a
 
      22nd Jun 2006
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]
- (E-Mail Removed)

"ano" <(E-Mail Removed)> wrote in message
news:8BBE0889-233A-407B-9D5F-(E-Mail Removed)...
> 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



 
Reply With Quote
 
=?Utf-8?B?RGF2aWQgQW50b24=?=
Guest
Posts: n/a
 
      22nd Jun 2006
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

 
Reply With Quote
 
Stoitcho Goutsev \(100\)
Guest
Posts: n/a
 
      22nd Jun 2006
Ano,


You should use | instead of ||

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


--
HTH
Stoitcho Goutsev (100)


"ano" <(E-Mail Removed)> wrote in message
news:8BBE0889-233A-407B-9D5F-(E-Mail Removed)...
> 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



 
Reply With Quote
 
=?Utf-8?B?YW5v?=
Guest
Posts: n/a
 
      22nd Jun 2006
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" <(E-Mail Removed)> wrote in message
> news:8BBE0889-233A-407B-9D5F-(E-Mail Removed)...
> > 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

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Configure Win2K "Search" Boolean "AND" operator Clueless in Seattle Microsoft Windows 2000 1 19th Apr 2008 02:39 PM
Convert VB to C#, Operator "Not" =?Utf-8?B?YW5v?= Microsoft C# .NET 5 26th Jun 2006 01:08 PM
Text "comparison" operator for "contains" used in an "IF" Function =?Utf-8?B?UGF3YXNv?= Microsoft Excel Worksheet Functions 3 19th Jan 2006 06:42 PM
LOTUS TRANSITION KEYS "/" "R" / "V" convert formulas to text. =?Utf-8?B?Ym9iQGdvcmRvbmVuZ2luZWVyaW5nLmNvbQ==?= Microsoft Access Getting Started 3 18th Jan 2006 09:15 AM
Outlook 2003: No "AND" "OR" operator in message rules Richard Microsoft Outlook 0 9th Jan 2004 08:27 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:23 AM.