The & operator can be either a unary operator or a two-dollar operator.
Note
The unary & operator returns the address of the operand (requires an unsafe context).
For integral type andthe bool type pre-defines the binary & operator. for integer,&, the Logical bitwise "and" of the operands are computed. bool operands, & Computes the logical AND of its operands; That is, the result was true if and only if both it operands is Span Class="input">true . For , bool operands,& The logical "and" of the operands, that is, when and only if the two operands are true , the result is true.
The & operator calculates two operators, regardless of the value of the first operand. For example:
1 int i = 0 2 False & ++i = = 1 ) 3 { 4 // I was incremented, but the conditional 5 expression evaluates to False, so 6 //
This block does not execute. 7 }
View Code
User-defined types can overload the $ two & operator (see operator). An operation that is applicable to an integer type usually applies to an enumeration type. when you overload the two-tuple operator, the corresponding assignment operator, if any, is also implicitly overloaded.
Example
1 classBitwiseand2 {3 Static voidMain ()4 {5 //The following statements perform logical ANDs.6Console.WriteLine (true&false); 7Console.WriteLine (true&true); 8 9 //The following line performs a bitwise AND of F8 (1111) andTen //3F (0011 1111). One //1111 A //0011 1111 - // --------- - //0011 or a theConsole.WriteLine ("0x{0:x}",0xf8&0x3f); - } - } - //Output: + //False - //True + //0x38View Code
& Operators