The logical operators of the ASP and other operators

Source: Internet
Author: User
Tags true true

The logical (Boolean) operator is used to perform an operation on an expression of the Boolean result, and the result of the operation is a Boolean. The results of the operation are as follows:

Operator Operation Example Results
& and (with) False&true false
| or (or) false|true true
^ xor (XOR) False^true true
! Not (non)!false true
&& (short circuit) false&&true false
|| OR (Short circuit) false| | True True


Here are some simple explanations for some of the more prone issues:

1, "^" will calculate the logical "XOR" of the operand; that is, the result is true when and only if only one operand is true.

2. The difference between "&" and "&&" is that if you use the former connection, the expressions on both sides of the "&" will participate in the calculation, regardless of the circumstances. If you use the latter connection, the expression on the right side of the "&&" will not be evaluated if it is false on the left. From:http://www.111cn.net/net/net/47469.htm

3, "|" with "| |" The difference is, "|" Indicates that either of the Boolean expressions on either side is true, the combination returns a true value, and for "| |", the second almost, if the left is true, returns True, if the left side is Falsh, then the right side, if true on the right, is true otherwise falsh.

Cases

Code to copy code as follows
Using System;
Using System.Data;
Using System.Configuration;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Web.UI.HtmlControls;

public partial class _default:system.web.ui.page
{
protected void Page_Load (object sender, EventArgs e)
{

int x = 0;
String name = "Search Bar";

& Operations, two of any of which is false is false
Response.Write ("X! = 0 & name =/" Search bar/"The result of the operation is:" + (x! = 0 & name = = "Search bar"));

Response.Write ("<br>");

| operation, when either of the two is true, the result of the operation is true, otherwise it is added
Response.Write ("X! = 0 | The result of the name =/"Search bar/" is: "+ (x! = 0 | name = =" Search bar "));

Response.Write ("<br>");

^ operation, when and only if one is true, is true, otherwise false
Response.Write ("X! = 0 ^ name =/" Search bar/"The result of the operation is:" + (x! = 0 ^ Name = = "Search bar"));
Response.Write ("<br>");
Response.Write ("x = = 0 ^ name =/" Search bar/"The result of the operation is:" + (x = = 0 ^ Name = = "Search bar"));
Response.Write ("<br>");

(www.111cn.net)//! operation, if True false, if False is true
The result of Response.Write ("X! = 0" is: "+! ( X! = 0));

Response.Write ("<br>");

&& short-circuit operation, if the left is false then exit, if the left is true, then look to the right
Response.Write ("X! = 0 && name =/" Search bar/"The result of the operation is:" + (x! = 0 && Name = = "Search bar"));

Response.Write ("<br>");
//|| Short-circuit operation, if the left is true, the true exit, if the left is false, then look to the right, the right is true, or false
Response.Write ("X! = 0 | | The result of the name =/"Search bar/" is: "+ (x! = 0 | | name = =" Search "));
}
}


Operator

C # provides a number of operators, which are symbols that specify what actions are performed in an expression. Integer operations are generally allowed for enumerations such as = =,! =, <, >, <=, >=, binary +, binary-, ^, &, |, ~, + + 、--, and sizeof (). In addition, many operators can be overloaded by the user, thereby changing the meaning of these operators when applied to user-defined types.

Operator category operator
Basic x.y
F (x)
A[x]
x + +
x--
New
typeof
Checked
unchecked
-
unary +
-
!
~
++x
--x
(T) x
True
False
&
sizeof
Multiply *
/
%
Add +
-
transform <<
> >
Relationship and type detection <

<=
>=
is
as
equality = =
! =
Logical AND &
Logical XOR ^
Logic or |
Condition and &&
Condition OR | |
Conditional operation?:
Assignment =
+ =
-=
*=
/=
% =
&=
|=
^=
<<=
>>=
??

Operator Precedence
Before + + + (plus sign)-(minus)! ~
* / %
+ -
<< >>
< > <= >=
== !=
&
^
|
&&
||
Assignment operations
After + + +--
Overloaded operators
C # allows user-defined types to overload operators by defining static member functions using the operator keyword. But not all operators can be overloaded, and the following table lists the operators that cannot be overloaded:
operator can be overloaded
+ 、-、!、 ~, + + 、--、 true and false to overload these unary operators.
+,-, *,/,%, &, |, ^, <<, >> you can overload these binary operators.
= =,! =, <, <=;, >= the comparison operator can be overloaded (but see the instructions later in this table).
&&, | | Conditional logical operators cannot be overloaded, but can be overloaded with & and | For calculation.
[] Array index operators cannot be overloaded, but indexers can be defined.
() You cannot overload conversion operators, but you can define new conversion operators (see explicit and implicit).
+ =,-=, *=,/=,%=, &=, |=, ^=, <<=, >>= assignment operators cannot be overloaded, but + = can use + compute, and so on.
= 、.、?:,,, New, is, sizeof, and TypeOf cannot overload these operators.

Grammar
public static Complex operator + (Complex C1, Complex C2)

The logical operators of the ASP and other operators

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.