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
热门推荐
10 朋友新年祝福语大全 简短
11 新年祝福语简短大方兔年
12 搬新家礼物祝福语简短
13 同学见面花束祝福语简短
14 五一假期祝福语幽默简短
15 离职欢送敬酒祝福语简短
16 对学弟的祝福语简短
17 考老师辞职祝福语简短
18 祝福语驱散霉运的话简短