if语句由一个布尔表达式后跟一个或多个语句组成。
C#中IF语句的语法是-
if(boolean_expression) { /* statement(s) will execute if the boolean expression is true */ }
using System; namespace DecisionMaking { class Program { static void Main(string[] args) { /* 局部变量定义 */ int a = 10; /* 使用 if 语句检查布尔条件 */ if (a < 20) { /* 如果条件为真,则打印以下内容 */ Console.WriteLine("a is less than 20"); } Console.WriteLine("value of a is : {0}", a); Console.ReadLine(); } } }
编译并执行上述代码时,将生成以下输出-
链接:https://www.learnfk.comhttps://www.learnfk.com/csharp/if-statement-in-csharp.html
来源:LearnFk无涯教程网
a is less than 20; value of a is : 10
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)