VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > temp > C#教程 >
  • c#中的 bool 关键字

c# 中的 bool 关键字

关键词 是一种语言中用于某种内部过程或代表某种预定义动作的词语。 bool 是一个关键字,用于声明一个可以存储布尔值 true 或 false 的变量。是系统的别名。布尔

Bool 关键字占用内存 1 字节(8 位)。bool 只有两种可能的值,即

语法:

bool variable_name = value;

示例:

Input: true

Output: answer: False
        Size of a byte variable: 1

Input: false

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

例 1:

// C# program for bool keyword
using System;
using System.Text;

    class GFG
    {
        static void Main(string[] args)
        { 
            // bool variable declaration
            bool answer = false;

            // to print value
            Console.WriteLine("answer: " + answer);

            // to print size of a bool 
            Console.WriteLine("Size of a bool variable: " + sizeof(bool));

        }
    }

输出:

answer: False
Size of a bool variable: 1

例 2:

// C# program for bool keyword
using System;
using System.Text;

namespace geeks {

class GFG {

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

        // to print type of variable
        Console.WriteLine("Type of answer: " + answer.GetType());

        // to print value
        Console.WriteLine("answer: " + answer);

        // to print size of a bool
        Console.WriteLine("Size of a bool variable: " + sizeof(bool));

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

输出:

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


相关教程