/*
关系运算符
判断两个数据之间大/小/相等关系的运算符
运算结果为Bool类型
即true或false
*/
using System;
public class HelloWorld
{
public static void Main()
{
Console.WriteLine("-------关系运算符-------------");
//举例
int A = 10, B = 20;
Console.WriteLine("A = 10,B = 20");
Console.WriteLine("A == B:" + (A == B));
Console.WriteLine("A != B:" + (A != B));
Console.WriteLine("A > B:" + (A > B));
Console.WriteLine("A < B:" + (A < B));
Console.WriteLine("A <= B:" + (A <= B));
Console.WriteLine("A >= B:" + (A >= B));
Console.WriteLine("-------逻辑运算符-------------");
//举例
int height = 180;
Console.WriteLine("height > 175 & height < 190:" + (height > 175 & height < 190));
Console.WriteLine("height > 175 | height < 190:" + (height > 175 | height < 190));
Console.WriteLine("!(height > 190):" + !(height > 190));
Console.WriteLine("height > 175 ^ height < 190:" + (height > 175 ^ height < 190));
//当前的数值大于0,小于10,且是偶数
int Num = 7;
int Remainder = Num % 2;
Console.WriteLine("==========例题=========");
Console.WriteLine((Num > 0 & Num < 10 & Remainder == 0 ));
Console.WriteLine("-------短路逻辑运算符-------------");
int OneNum = 5;
Console.WriteLine(OneNum > 8 & ++OneNum > 5);
Console.WriteLine(OneNum);
int TwoNum = 5;
Console.WriteLine(TwoNum > 8 && ++TwoNum > 5); //当判断到前方为false,则不执行后续语句,++TwoNum也不执行
Console.WriteLine(TwoNum);
int ThreeNum = 5;
Console.WriteLine(ThreeNum > 8 | ++ThreeNum > 5);
Console.WriteLine(ThreeNum);
int FourNum = 5;
Console.WriteLine(FourNum < 8 || ++FourNum < 2); //当判断到前方为true,则不执行后续语句,++FourNum也不执行
Console.WriteLine(FourNum);
}
}