<分区>
Possible Duplicate:
What is the difference between Bool and Boolean types in C#
为什么 C# 对 boolean 类型使用单词 bool
而不是 boolean
?
(我只是浪费了 5 分钟试图找出为什么我的代码没有编译!)
<分区>
Possible Duplicate:
What is the difference between Bool and Boolean types in C#
为什么 C# 对 boolean 类型使用单词 bool
而不是 boolean
?
(我只是浪费了 5 分钟试图找出为什么我的代码没有编译!)
最佳答案
大概是因为这是 C++ 为其 boolean 类型使用的关键字,而 C# 保留了很多语法以帮助熟悉该语言的程序员更轻松地迁移。旧习难改。
它也更短,可以节省输入。程序员是出了名的懒惰,这是有充分理由的。
但请记住,bool
在 C# 中只是 System.Boolean
的一个别名类型。如果愿意,您当然可以使用 Boolean
(当然,您必须将其大写,因为 C# 区分大小写)。
关于C#:为什么是 'bool' 而不是 'boolean',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5229850/