สำหรับชนิดข้อมูล Boolean ใช้คีย์เวิร์ด bool ซึ่งเป็นนามแฝงของ System.Boolean
ใช้สำหรับประกาศตัวแปรเก็บค่า Boolean คือ true และ false
ตัวอย่าง
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");
}
}
}