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(); } } } /** * <(小於) 檢查左操作數的值是否小於右操作數的值,如果是則條件爲真。 * <=(小於等於) 檢查左操作數的值是否小於或等於右操作數的值,如果是則條件爲真。 * >(大於) 檢查左操作數的值是否大於右操作數的值,如果是則條件爲真。 * >=(大於等於) 檢查左操作數的值是否大於或等於右操作數的值,如果是則條件爲真。 * !=(不等於) 檢查兩個操作數的值是否相等,如果不相等則條件爲真。 * ==(等於) 檢查兩個操作數的值是否相等,如果相等則條件爲真。 * */
七、運算符之關係運算符
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.