9, C # inside the relationship expression, logical expression

Source: Internet
Author: User

In the programming of C # language, relational expressions and logical expressions are often used, or mixed use of both.


1. relational expressions are made up of relational operators. For example:>,<,>=,<=,= = ,!=. An expression that uses these operators is called a relational expression. Examples are as follows:

int number_01;

int number_02;

Enter A value for number_01

Console.Write (" Please enter The value of number_01:");

Number_01=console.readline ();

Enter A value for number_02

Console.Write (" Please enter The value of number_02:");

Number_02=console.readline ();


if (number_01==number_02)

{

Console.WriteLine ("Number_01 and number_02 equal ");

}


if (number_01!=number_02)

{

Console.WriteLine ("Number_01 and number_02 Not equal ");

}


if (number_01>number_02)

{

Console.WriteLine ("Number_01 greater than number_02");

}


if (number_01>=number_02)

{

Console.WriteLine ("Number_01 greater than or equal to number_02");

}


if (number_01<number_02)

{

Console.WriteLine ("Number_01 less than number_02");

}


if (number_01<=number_02)

{

Console.WriteLine ("Number_01 less than or equal to number_02");

}


2. logical expressions are made up of logical operators. Mainly include:&,| , ! , ^ .

rules for logic and & :

Logical and logical values on both sides are true, the result is true; otherwise false.

True&true=true

True&false=false

False&true=false

False&false=false


Logical OR rule:

Logical or logical values on either side are true, as long as there is one, the result is true.

True|true=true

True|false=true

False|true=true

False|false=false


The logic is not to take the opposite value.

! false=true

!true=false


Logical XOR:

Logical XOR is false for both sides of the value , and the other case is true.

True^true=false

True^false=true

False^true=true

False^false=false


This article is from the "Smile" blog, please be sure to keep this source http://yiyiweixiao.blog.51cto.com/2476874/1969133

9, C # inside the relationship expression, logical expression

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.