温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

七、运算符之关系运算符

发布时间:2020-08-02 13:00:10 来源:网络 阅读:491 作者:vik_xiao 栏目:编程语言
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();
        }
    }
}

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


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI