C#:为什么是“布尔"而不是“布尔" [英] C#: why 'bool' instead of 'boolean'

查看:34
本文介绍了C#:为什么是“布尔"而不是“布尔"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
布尔类型和布尔类型有什么区别C#

为什么 C# 使用单词 bool 而不是 boolean 来表示布尔类型?

Why does C# use the word bool intead of boolean for boolean types?

(我只是浪费了 5 分钟试图找出我的代码无法编译的原因!)

(I just wasted 5 mins trying to work out why my code wasn't compiling!)

推荐答案

大概是因为这是 C++ 用于其布尔类型的关键字,而 C# 保留了大部分语法以帮助熟悉该语言的程序员更轻松地迁移.旧习惯难改.

Presumably because that's the keyword C++ uses for its boolean type, and C# retains much of the syntax to help programmers comfortable with that language migrate more easily. Old habits die hard.

它也更短,可以节省打字时间.程序员是出了名的懒惰,这是有充分理由的.

It's also shorter, which saves typing. Programmers are a notoriously lazy bunch, and for good reason.

但请记住,bool 只是 C# 中 System.Boolean 类型.如果您愿意,当然可以使用 Boolean 代替(当然,您必须将其大写,因为 C# 区分大小写).

But remember that bool is only an alias in C# for the System.Boolean type. You can certainly use Boolean instead if you prefer (but of course, you'll have to capitalize it, since C# is case-sensitive).

这篇关于C#:为什么是“布尔"而不是“布尔"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆