473,382 Members | 1,428 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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 6243
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sean Dettrick | last post by:
Hi, I have several <vector>'s of the same length, with entries as follows: I= A= B= I want to use STL to make (I == 0) a mask to operate on the elements of A and B, i.e. I want to do this:
4
by: Bradley Plett | last post by:
I have what should be a trivial problem. I am using XMLSerializer to serialize an object. It serializes boolean values as "True" and "False". I then want to use an XSLT on this XML, and I want...
3
by: Cybertof | last post by:
Hello, I would like to return the good single value from a string value in these cases : Convert.ToSingle("23,30"); Convert.ToSingle("23.30"); // Conversion Error !!! The result should be...
1
by: RajS | last post by:
Hi All, I wanted increase time out on odbc connection, I have code like this this.odbcConnection1.set_ConnectionTimeout(1000); I got the following error "cannot explicitly call operator or...
2
by: andrew007 | last post by:
I do xml / xslt transformation using asp.net but I found any value (w/xml format) in xml node html-encoded to &lt and &gt format if it's > or < tag. Since I have sub xml data in a parent xml node...
5
by: han zhiyang | last post by:
Hi. I tried to design a custom web control which can flexibly and dynamicly let the control user ,for example the web page developer, customize its layout codes.This control derives from...
2
by: Serious_Practitioner | last post by:
Good day, and thank you in advance for any assistance. I'm having trouble with something that I'm trying for the first time. Using Access 2000 - I want to run a function either on the click of a...
37
by: jht5945 | last post by:
For example I wrote a function: function Func() { // do something } we can call it like: var obj = new Func(); // call it as a constructor or var result = Func(); // call it as...
6
by: Russ P. | last post by:
I've always appreciated Python's lack of requirement for a semi-colon at the end of each line. I also appreciate its rules for automatic line continuation. If a statement ends with a "+", for...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.