Siki asked us to check the difference between & and && so ...
1) & and && can be used as the logical AND operator, representing the logic and (and), when the result of an expression on either side of the operator is true, the entire result is true, otherwise, the result is false if one of the parties is false.
2) && also has a short-circuit function, that is, if the first expression is false, the second expression is no longer evaluated, for example, for an if (str! = null &&!str.equals (")) expression, when STR is NULL, The subsequent expression will not be executed, so nullpointerexception will not appear, and if && is changed to &, then it will continue to determine whether equals, and actually STR is NULL, The NullPointerException exception is thrown. In the example below, if (x==33 & ++y>0) y grows, if (x==33 && ++y>0) does not grow
int x = n; int y = 2; if (x >= && ++y > 0) { Console.WriteLine (y); } Console.WriteLine (y); if (x >= & y++ > 0) { Console.WriteLine (y); } Console.WriteLine (y); Console.readkey ();
3) & can also be used as a bitwise operator, when an expression on either side of the & operator is not a Boolean,,& represents bitwise AND operation, and we typically use 0x0f to perform a & operation with an integer to get the minimum 4 bit bits of that integer, for example, 0x31 & the result of 0x0f is 0x01.
The difference between & and && in C #