c# bool?和bool_C#中的bool关键字

c# bool?和bool

C#bool关键字 (C# bool keyword)

In C#, bool is a keyword which is used to declare a variable that can store Boolean values true or false. bool keyword is an alias of System.Boolean.

在C#中, bool是一个关键字,用于声明可以存储布尔值true或false的变量。 bool关键字是System.Boolean的别名。

It occupies 1 byte (8 bits) in the memory.

它在内存中占用1个字节(8位)。

Syntax:

句法:

    bool variable_name = value;

There are only two possible values that can be assigned to a bool variable 1) true or 2) false

只能将两个可能的值分配给布尔变量1) true或2) false

C#代码演示bool关键字示例 (C# code to demonstrate example of bool keyword)

Here, we are declaring a bool variable answer, initializing it with the value true and printing its value, type, and size of a bool type variable.

在这里,我们声明一个布尔变量答案 ,将其初始化为值true,并打印其值,类型和布尔类型变量的大小。

using System;
using System.Text;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            //bool variable declaration
            bool answer = true;

            //printing value
            Console.WriteLine("answer: " + answer);
            //printing type of variable
            Console.WriteLine("Type of answer: " + answer.GetType());
            //printing size of a bool 
            Console.WriteLine("Size of a bool variable: " + sizeof(bool));

            //hit ENTER to exit
            Console.ReadLine();
        }
    }
}

Output

输出量

answer: True
Type of answer: System.Boolean
Size of a bool variable: 1


翻译自: https://www.includehelp.com/dot-net/bool-keyword-in-c-sharp.aspx

c# bool?和bool

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值