C# 中的布尔类型是什么?
csharpprogrammingserver side programming更新于 2025/9/20 11:22:17
对于布尔类型,使用 bool 关键字,它是 System.Boolean 的别名。
它用于声明用于存储布尔值 true 和 false 的变量。
让我们通过一个例子来学习如何在 C# 中使用 bool。
示例
using System;
public class Demo {
static void Main() {
bool val = true;
int d = DateTime.Now.DayOfYear;
val = (d % 2 == 0);
if (val) {
Console.WriteLine("days: even number");
} else {
Console.WriteLine("days:odd number");
}
}
}

