码迷,mamicode.com
首页 > 其他好文 > 详细

七、运算符之关系运算符

时间:2014-12-04 06:35:02      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:c#   .net   .net framework   编程   移动开发   

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();
        }
    }
}

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


本文出自 “MK IT Life” 博客,请务必保留此出处http://vikxiao.blog.51cto.com/9189404/1586109

七、运算符之关系运算符

标签:c#   .net   .net framework   编程   移动开发   

原文地址:http://vikxiao.blog.51cto.com/9189404/1586109

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!