The &, ^, and | operators are called the logical operators.

*and-expression:equality-expressionand-expression & equality-expression*

*exclusive-or-expression:and-expressionexclusive-or-expression ^ and-expression*

*inclusive-or-expression:exclusive-or-expressioninclusive-or-expression | exclusive-or-expression*

For an operation of the form x *op* y, where *op* is one of the logical operators, overload resolution is applied to select a specific operator implementation. The operands are converted to the parameter types of the selected operator, and the type of the result is the return type of the operator.

The predefined logical operators are described in the following sections.

### Integer logical operators

The predefined integer logical operators are:

int operator &(int x, int y);

uint operator &(uint x, uint y);

long operator &(long x, long y);

ulong operator &(ulong x, ulong y);

int operator |(int x, int y);

uint operator |(uint x, uint y);

long operator |(long x, long y);

ulong operator |(ulong x, ulong y);

int operator ^(int x, int y);

uint operator ^(uint x, uint y);

long operator ^(long x, long y);

ulong operator ^(ulong x, ulong y);

The & operator computes the bitwise logical AND of the two operands, the | operator computes the bitwise logical OR of the two operands, and the ^ operator computes the bitwise logical exclusive OR of the two operands. No overflows are possible from these operations.

### Enumeration logical operators

Every enumeration type E implicitly provides the following predefined logical operators:

E operator &(E x, E y);

E operator |(E x, E y);

E operator ^(E x, E y);

The result of evaluating x *op* y, where x and y are expressions of an enumeration type E with an underlying type U, and *op* is one of the logical operators, is exactly the same as evaluating (E)((U)x *op* (U)y). In other words, the enumeration type logical operators simply perform the logical operation on the underlying type of the two operands.

### Boolean logical operators

The predefined boolean logical operators are:

bool operator &(bool x, bool y);

bool operator |(bool x, bool y);

bool operator ^(bool x, bool y);

The result of x & y is true if both x and y are true. Otherwise, the result is false.

The result of x | y is true if either x or y is true. Otherwise, the result is false.

The result of x ^ y is true if x is true and y is false, or x is false and y is true. Otherwise, the result is false. When the operands are of type bool, the ^ operator computes the same result as the != operator.

### Nullable boolean logical operators

The nullable boolean type bool? can represent three values, true, false, and null, and is conceptually similar to the three-valued type used for boolean expressions in SQL. To ensure that the results produced by the & and | operators for bool? operands are consistent with SQL’s three-valued logic, the following predefined operators are provided:

bool? operator &(bool? x, bool? y);

bool? operator |(bool? x, bool? y);

The following table lists the results produced by these operators for all combinations of the values true, false, and null.

x | y | x & y | x | y |

true | true | true | true |

true | false | false | true |

true | null | null | true |

false | true | false | true |

false | false | false | false |

false | null | false | null |

null | true | null | true |

null | false | false | null |

null | null | null | null |

Content

License.

All information of this service is derived from the free sources and is provided solely in the form of quotations.
This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.

Copyright 2016 © ELTASK.COM. All rights reserved.

Site is optimized for mobile devices.

Downloads: 3644 / . Delta: 0.05103 с

Site is optimized for mobile devices.

Downloads: 3644 / . Delta: 0.05103 с