c 运算符##

Relational operators are used to compare the values and returns Boolean values, if condition is true – they return True, otherwise they return False.

关系运算符用于比较值并返回布尔值(如果condition为true)-它们返回True ,否则返回False 。

Here is the list of relation operators,

这是关系运算符的列表,

  1. "==" (Equal To) – it returns true, if both operand’s values are equal

    “ ==”(等于) –如果两个操作数的值相等,则返回true

  2. "!=" (Not Equal To) – it returns true, if both operand’s values are not equal

    “!=”(不等于) –如果两个操作数的值都不相等,则返回true

  3. " – it returns true if first, operand is less than second operand

    “ –如果第一个操作数小于第二个操作数,则返回true

  4. "<=" (Less Than or Equal To) – it returns true, if either first operand is less than or equal to second operand

    “ <=”(小于或等于) –如果第一个操作数小于或等于第二个操作数,则返回true

  5. ">" (Greater Than) – it returns true, if first operand is greater than second operand

    “>”(大于) –如果第一个操作数大于第二个操作数,则返回true

  6. ">=" (Greater Than or Equal To) – it returns true, if either first operand is greater than or equal to second operand

    “> =”(大于或等于) –如果第一个操作数大于或等于第二个操作数,则返回true

Syntax:

句法:

    Operand1 == Operand2
Operand1 != Operand2
Operand1 < Operand2
Operand1 <= Operand2
Operand1 > Operand2
Operand1 >= Operand2

Example:

例:

    Input:
int a = 10;
int b = 3;
Console.WriteLine("a==b: {0}", (a == b));
Console.WriteLine("a!=b: {0}", (a != b));
Console.WriteLine("a>b : {0}", (a > b));
Console.WriteLine("a>=b: {0}", (a >= b));
Console.WriteLine("a<b : {0}", (a < b));
Console.WriteLine("a<=b: {0}", (a <= b));
Output:
a==b: False
a!=b: True
a>b : True
a>=b: True
a<b : False
a<=b: False

C# code to demonstrate example of relational operators

C#代码演示关系运算符的示例

// C# program to demonstrate example of
// relational operators
using System;
using System.IO;
using System.Text;
namespace IncludeHelp
{class Test
{// Main Method
static void Main(string[] args)
{int a = 10;
int b = 3;
//printing return type
Console.WriteLine("Return type of == operator: {0}", (a == b).GetType());
Console.WriteLine("Return type of != operator: {0}", (a != b).GetType());
Console.WriteLine("Return type of > operator : {0}", (a > b).GetType());
Console.WriteLine("Return type of >= operator: {0}", (a >= b).GetType());
Console.WriteLine("Return type of < operator : {0}", (a < b).GetType());
Console.WriteLine("Return type of <= operator: {0}", (a <= b).GetType());
//printing return values
Console.WriteLine("a==b: {0}", (a == b));
Console.WriteLine("a!=b: {0}", (a != b));
Console.WriteLine("a>b : {0}", (a > b));
Console.WriteLine("a>=b: {0}", (a >= b));
Console.WriteLine("a<b : {0}", (a < b));
Console.WriteLine("a<=b: {0}", (a <= b));
//checking conditions
if (a == b)
Console.WriteLine("a is equal to b");
else
Console.WriteLine("a is not equal to b");
if (a != b)
Console.WriteLine("a is not equal to b");
else
Console.WriteLine("a is equal to b");
if (a > b)
Console.WriteLine("a is greater than b");
else
Console.WriteLine("a is not greater than b");
if (a >= b)
Console.WriteLine("a is greater than or equal to b");
else
Console.WriteLine("a is not greater than or equal to b");
if (a < b)
Console.WriteLine("a is less than b");
else
Console.WriteLine("a is not less than b");
if (a <= b)
Console.WriteLine("a is less than or equal to b");
else
Console.WriteLine("a is not less than or equal to b");
//checking conditions in another way
if ((a == b) == true)
Console.WriteLine("a is equal to b");
else
Console.WriteLine("a is not equal to b");
if ((a != b) == true)
Console.WriteLine("a is not equal to b");
else
Console.WriteLine("a is equal to b");
if ((a > b) == true)
Console.WriteLine("a is greater than b");
else
Console.WriteLine("a is not greater than b");
if ((a >= b) == true)
Console.WriteLine("a is greater than or equal to b");
else
Console.WriteLine("a is not greater than or equal to b");
if ((a < b) == true)
Console.WriteLine("a is less than b");
else
Console.WriteLine("a is not less than b");
if ((a <= b) == true)
Console.WriteLine("a is less than or equal to b");
else
Console.WriteLine("a is not less than or equal to b");
//hit ENTER to exit the program
Console.ReadLine();
}
}
}

Output

输出量

Return type of == operator: System.Boolean
Return type of != operator: System.Boolean
Return type of > operator : System.Boolean
Return type of >= operator: System.Boolean
Return type of < operator : System.Boolean
Return type of <= operator: System.Boolean
a==b: False
a!=b: True
a>b : True
a>=b: True
a<b : False
a<=b: False
a is not equal to b
a is not equal to b
a is greater than b
a is greater than or equal to b
a is not less than b
a is not less than or equal to b
a is not equal to b
a is not equal to b
a is greater than b
a is greater than or equal to b
a is not less than b
a is not less than or equal to b

翻译自: https://www.includehelp.com/dot-net/relational-operators-example-in-c-sharp.aspx

c 运算符##

c 运算符##_C#程序演示关系运算符的示例相关推荐

  1. linux运算_CentOS「linux」学习笔记22:算术运算符、逻辑运算符、关系运算符

    ​linux基础操作:主要介绍啦算术运算符.逻辑运算符.关系运算符 1.算术运算符[主要用来计算数值] 注意使用expr运算时运算符和数值之间需要有空格,其他方式运算时不能有空格. 常用算术运算符号: ...

  2. C++primer 第 4 章 表达式 4.1基础 4 . 2 算术运算符 4 .3 逻辑和关系运算符 4 . 4 赋值运算符 4 .5 递增和递减运算符 4.6成员访问运算符

    表达式由一个或多个运算对象(operand)组成,对表达式求值将得到一个结果(result) 字面值和变量是最简单的表达式(expression),其结果就是字面值和变量的值.把一个运算符(opera ...

  3. c语言由高到低的运算符,求解C语言关系运算符优先极由高到低列表(同级请用括号)...

    满意答案 一般而言,单目运算符优先级较高,赋值运算符优先级低.算术运算符优先级较高,关系和逻辑运算符优先级较低.多数运算符具有左结合性,单目运算符.三目运算符.赋值运算符具有右结合性. 恩,问这个问题 ...

  4. c#如何嵌套第三方程序_C#程序演示嵌套条件运算符的示例

    c#如何嵌套第三方程序 C# (or other programming languages also) allows to use a conditional/ternary operator wi ...

  5. c++算术运算符、逻辑运算符、关系运算符

    一.算术运算符 1.包括一元运算符 +,- 和二元运算符 +,-,*,/ . 2.c++11中两个整数相除(不论正负)商向0取整,即切除小数部分. 3.新的c++标准中,m % (-n) = m % ...

  6. python幂运算符_Python程序使用指数运算符查找数字的幂

    python幂运算符 Given two numbers a and b, we have to find a to the power b using exponential operator (* ...

  7. mysql数据库访问程序_c++程序访问MySQL数据库操作示例

    1.安装mysql sudo apt-get install mysql-server mysql-client 安装过程中会提示设置用户名和密码 2.启动mysql sudo /etc/init.d ...

  8. C语言关系运算符介绍和示例

    文章目录 1.关系运算符介绍 2.应用示例 3.获取视频教程 4.版权声明 1.关系运算符介绍 关系运算(Relational Operators),用于判断条件,决定程序的流程. 关系 数学中的表示 ...

  9. C语言基础知识:关系运算符与逻辑运算符

    目录 1.关系运算符介绍 2.应用示例 3.逻辑运算符介绍 4.逻辑表达式的书写 5.不得不说的逻辑非 1.关系运算符介绍 关系运算(Relational Operators),用于判断条件,决定程序 ...

最新文章

  1. Python爬虫1-Scrapy环境的安装
  2. VC中BSTR和CString的使用
  3. 【转】NSMutableArray的正确使用
  4. VHDL硬件描述语言
  5. LeetCode_字符串类
  6. Chrome浏览器兼容性 检测工具 (chrome插件)
  7. linux的can通信busoff,socketCAN内核源码分析是否支持busoff自恢复--Apple的学习笔记
  8. DebugDiag调试工具
  9. CCS软件的Graph功能
  10. Planetside.Software.Terragen.v0.9.43.WinALL 1CD(景观产生器)
  11. 大数据项目实战-电商日志平台
  12. [游泳] 游泳学习课程
  13. @Scheduled注解与参数
  14. 学习PCB之pcb器件的绘制
  15. ESP32-Arduino开发实例-与Arduino之间SPI通信
  16. 4G无线模块 电力通信模块
  17. 华为荣耀note10计算机在哪找,华为荣耀note10如何使用电脑模式-华为云电脑使用方法介绍 - Iefans...
  18. What I've learnt today(from youtube videos and comments)
  19. 烦恼天天有,不捡自然无
  20. 编号10003 网络工程师(p5-p7)

热门文章

  1. vscode连接远程服务器 SSH
  2. LDAP命令介绍---dstune
  3. Give Candies【快速幂+欧拉】
  4. 【数据结构和算法05】 红-黑树(转发)
  5. JS中调用bignumber处理高精度小数运算
  6. Citrix Netscaler版本管理和选择
  7. android学习之-Style样式的定义
  8. 如何快速精确的和leader沟通
  9. 【项目经验】如何用TexturePacker Physicseditor开发游戏
  10. 昨天安装复习中遇到的问题小结