C# 中的 Bool 数组
csharpprogrammingserver side programming更新于 2025/9/17 15:34:00
在 bool 数组中,可以存储 true 和 false 值。要设置 bool 数组,请使用 new 运算符 −
bool[] arr = new bool[5];
要在数组中添加元素 −
arr[0] = true; arr[1] = true; arr[2] = false; arr[3] = true; arr[4] = true;
让我们看看完整的代码 −
示例
using System;
public class Demo {
public static void Main() {
bool[] arr = new bool[5];
arr[0] = true;
arr[1] = true;
arr[2] = false;
arr[3] = true;
arr[4] = true;
Console.WriteLine("显示值...");
foreach (bool res in arr) {
Console.WriteLine(res);
}
}
}
输出
显示值... True True False True True

