Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

C# 比较运算符


比较运算符

比较运算符用于比较两个值(或变量)。这在编程中非常重要,因为它可以帮助我们找到答案并做出决策。

比较运算符的返回值要么是 True,要么是 False。这些值称为布尔值,您将在布尔值If..Else章节中了解更多关于它们的信息。

在下面的示例中,我们使用大于运算符 (>) 来确定 5 是否大于 3

示例

int x = 5;
int y = 3;
Console.WriteLine(x > y); // returns True because 5 is greater than 3

亲自尝试 »

所有比较运算符的列表

运算符 名称 示例 尝试
== 等于 x == y 尝试 »
!= 不等于 x != y 尝试 »
> 大于 x > y 尝试 »
< 小于 x < y 尝试 »
>= 大于或等于 x >= y 尝试 »
<= 小于或等于 x <= y 尝试 »

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.