Groups | Blog | Home
all groups > c# > january 2004 >

c# : c sharp operators


Aaron
1/13/2004 11:02:27 PM
whats the difference between || and | (OR) && and &(AND)?

Dave Quigley
1/14/2004 1:15:25 AM
|| and && are logical operators

they evaluate into this and that, or , this or that..


the single ones are bitwise operators

if i have the bit pattern 1111 and 1010 if i do 1111 | 1010 it will or each
bit with its corresponding bit in the other one resulting in 1111 if i do
1111 & 1010 it will result in 1010.
[quoted text, click to view]

Morten Wennevik
1/14/2004 8:18:15 AM
Consider

int a =3D 0;
int b =3D 0;

if((a =3D=3D 1) && (b =3D 1) =3D=3D 0){}

&& instead of & means, that if a !=3D 1, IF returns false without ever =

checking the second statement, whereas with
& both statements would be calculated

&& -> a =3D 0, b =3D 0
& -> a =3D 0, b =3D 1

Same with || and |. If the first statement is true || will ignore the =

second statement, whereas | will check both.

So, for || and && you run the risk that initiations happening in the =

second statements may or may not get done, but you will also benefit fro=
m =

not having to done lengthy initiations if doesn't need to be done since =

the if block would or wouldn't get executed anyway.


-- =

Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
For a laugh, try web browsing with Opera's User Mode with Nostalgia enab=
Morten Wennevik
1/14/2004 8:24:37 AM
If should start proof reading my English before clicking [Send] :P

-- =

Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
For a laugh, try web browsing with Opera's User Mode with Nostalgia enab=
Morten Wennevik
1/14/2004 8:30:23 AM
My point exactly

-- =

Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
For a laugh, try web browsing with Opera's User Mode with Nostalgia enab=
AddThis Social Bookmark Button