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

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 运算符##

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值