// C# 关键字示例代码
// 1. using 关键字:用于引入命名空间
using System;
// 2. class 关键字:用于定义类
class Program
{
// 3. static 关键字:用于定义静态成员或方法
static void Main(string[] args)
{
// 4. int 关键字:用于声明整数类型变量
int number = 10;
// 5. string 关键字:用于声明字符串类型变量
string message = "Hello, World!";
// 6. Console.WriteLine 方法:用于输出信息到控制台
Console.WriteLine(message);
// 7. if 关键字:用于条件判断
if (number > 0)
{
Console.WriteLine("The number is positive.");
}
// 8. for 关键字:用于循环
for (int i = 0; i < 5; i++)
{
Console.WriteLine($"Loop iteration {i}");
}
// 9. bool 关键字:用于声明布尔类型变量
bool isTrue = true;
// 10. return 关键字:用于返回值或退出方法
return;
}
}
以上代码展示了多个常见的C#关键字及其用法。
下一篇:c#四舍五入
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站