C#中的bool关键字
C#bool关键字
在C#中,bool是一个关键字,用于声明可以存储布尔值true或false的变量。bool关键字是System.Boolean的别名。
它在内存中占用1字节(8位)。
语法:
bool variable_name = value;
只能将两个可能的值分配给布尔变量1)true或2)false
C#代码演示bool关键字示例
在这里,我们声明一个布尔变量答案,将其初始化为值true,并打印其值,类型和布尔类型变量的大小。
using System;
using System.Text;
namespace Test
{
class Program
{
static void Main(string[] args)
{
//布尔变量声明
bool answer = true;
//打印值
Console.WriteLine("answer: " + answer);
//打印变量的类型
Console.WriteLine("Type of answer: " + answer.GetType());
//打印布尔大小
Console.WriteLine("Size of a bool variable: " + sizeof(bool));
//按ENTER退出
Console.ReadLine();
}
}
}输出结果
answer: True Type of answer: System.Boolean Size of a bool variable: 1
热门推荐
1 如何训练狗狗不叫
2 训练狗狗不叫
3 训练狗狗随行
4 怎么训练狗狗不叫
7 训练比熊狗狗教程
10 上海狗狗训练
11 怎么训练狗狗上厕所
12 训练狗狗趴下
13 狗狗服从训练
14 训练狗狗拒食
15 训练狗狗笑
16 训练狗狗大便
17 训练狗狗立
18 训练狗狗捡东西