469,591 Members | 2,093 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

problem with logical operator

Hi,
I have a value that contains flags that I must get using a bitmask. I tryied
with the && operator, but the compiler outputs this error :

Operator '&&' cannot be applied to operands of type 'int' and 'int'

The code is the following :

// MASKS.Insert = 2
if (_RightMask && (int)MASKS.Insert)
{
do something
}

I tried with and without the cast (int), but nothing works... Am I missing
something? it seems to be the right way of doing it but the compiler does
not allow it.

Thanks

ThunderMusic
Jan 19 '06 #1
2 3968
Use & instead of &&.

"ThunderMusic" wrote:
Hi,
I have a value that contains flags that I must get using a bitmask. I tryied
with the && operator, but the compiler outputs this error :

Operator '&&' cannot be applied to operands of type 'int' and 'int'

The code is the following :

// MASKS.Insert = 2
if (_RightMask && (int)MASKS.Insert)
{
do something
}

I tried with and without the cast (int), but nothing works... Am I missing
something? it seems to be the right way of doing it but the compiler does
not allow it.

Thanks

ThunderMusic

Jan 19 '06 #2
As Sergey says; use &.

& and | are the C# bitwise operators. They are also overloaded to be the C#
non-short-circuit logical operators. (&& and || are the short-circuit
logical operators.)

(In VB, "And" and "Or" are both the bitwise operators and non-short-circuit
logical operators, while "AndAlso" and "OrElse" are the short-circuit logical
operators).

--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter

"ThunderMusic" wrote:
Hi,
I have a value that contains flags that I must get using a bitmask. I tryied
with the && operator, but the compiler outputs this error :

Operator '&&' cannot be applied to operands of type 'int' and 'int'

The code is the following :

// MASKS.Insert = 2
if (_RightMask && (int)MASKS.Insert)
{
do something
}

I tried with and without the cast (int), but nothing works... Am I missing
something? it seems to be the right way of doing it but the compiler does
not allow it.

Thanks

ThunderMusic

Jan 19 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Jay Moore | last post: by
3 posts views Thread by Nagib Abi Fadel | last post: by
80 posts views Thread by Christopher Benson-Manica | last post: by
8 posts views Thread by Chua Wen Ching | last post: by
23 posts views Thread by Cor | last post: by
21 posts views Thread by Mike | last post: by
9 posts views Thread by marko | last post: by
3 posts views Thread by gallows | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.