七、运算符之关系运算符

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _7.运算符之关系运算符
{
    class Program
    {
        static void Main(string[] args)
        {
            // 关系运算符也称布尔比较运算符
            int a = 21, b = 10;
            
            // 小于(<)和小于等于(<=)
            Console.WriteLine("{0} < {1} = {2}", a, b, a < b);
            Console.WriteLine("{0} <= {1} = {2}", a, b, a <= b);
            
            // 大于(>)和大于等于(>=)
            Console.WriteLine("{0} > {1} = {2}", a, b, a > b);
            Console.WriteLine("{0} >= {1} = {2}", a, b, a >= b);
            
            // 不等于(!=)和等于(==)
            Console.WriteLine("{0} != {1} = {2}", a, b, a != b);
            Console.WriteLine("{0} == {1} = {2}", a, b, a == b);
            
            // !=和==也可应用于字符串的比较
            string str1 = "hello", str2 = "Hello";
            Console.WriteLine("\"{0}\" != \"{1}\" = {2}", str1, str2, str1 != str2);
            Console.WriteLine("\"{0}\" == \"{1}\" = {2}", str1, str2, str1 == str2);
            
            // !=和==也可应用于Bool类型的比较
            bool bool1 = true, bool2 = false;
            Console.WriteLine("{0} != {1} = {2}", bool1, bool2, bool1 != bool2);
            Console.WriteLine("{0} == {1} = {2}", bool1, bool2, bool1 == bool2);
            
            Console.ReadKey();
        }
    }
}

/**
 * <(小于)        检查左操作数的值是否小于右操作数的值,如果是则条件为真。
 * <=(小于等于)   检查左操作数的值是否小于或等于右操作数的值,如果是则条件为真。
 * >(大于)        检查左操作数的值是否大于右操作数的值,如果是则条件为真。
 * >=(大于等于)   检查左操作数的值是否大于或等于右操作数的值,如果是则条件为真。
 * !=(不等于)     检查两个操作数的值是否相等,如果不相等则条件为真。
 * ==(等于)       检查两个操作数的值是否相等,如果相等则条件为真。
 * 
 */

网站名称:七、运算符之关系运算符
网站链接:https://www.cdcxhl.com/article14/ppiige.html

成都网站建设公司_创新互联,为您提供手机网站建设品牌网站设计定制网站域名注册响应式网站网站内链

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

成都做网站