Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


What does && mean in C#

what dose && mean in C#

1 Answer

Steven Parker
Steven Parker
229,921 Points

It's the logical (boolean) operator for "and". You use it to combine things which in themselves produce "true" or "false" results.

For example:

if (height > 52 && height < 80)
    Console.WriteLn("Congratulations, you are allowed to ride this ride!");

For the if to be true, the height must be over 52 AND it must be less than 80.

whats the difference when using & and &&

Steven Parker
Steven Parker
229,921 Points

Just one "&" is a bitwise operator. It's also called and, but instead of combining things which are either true or false, it combines the bits of two values. For example:

x = 7;   // 0111 in binary
y = 12;  // 1100 in binary
z = x & y;  // z will be 4 (binary 0100)

FYI: there are similar operators for OR: "||" for logical, and "|" for bitwise.