Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / January 2006

Tip: Looking for answers? Try searching our database.

problem with logical operator

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ThunderMusic - 19 Jan 2006 04:47 GMT
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
Sergey Poberezovskiy - 19 Jan 2006 06:07 GMT
Use & instead of &&.

> Hi,
> I have a value that contains flags that I must get using a bitmask. I tryied
[quoted text clipped - 17 lines]
>
> ThunderMusic
David Anton - 19 Jan 2006 15:10 GMT
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).

Signature

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

> Hi,
> I have a value that contains flags that I must get using a bitmask. I tryied
[quoted text clipped - 17 lines]
>
> ThunderMusic

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.