c# - C# 中的 int 是 32 位的吗?

标签 c#

<分区>

我刚刚听说 int 的大小取决于机器。我一直以为int的大小是32位的。有人可以解释这个难题吗?

最佳答案

在 C# 中,int 类型始终是 Int32,并且始终是 32 位。

其他一些语言有不同的规则,int 可以是机器相关的。在某些语言中,int 被定义为具有最小大小,但机器/实现特定大小至少有那么大。例如,在 C++ 中,int 数据类型不一定是 32 位。来自 fundimental data types :

the general specification is that int has the natural size suggested by the system architecture (one "word") and the four integer types char, short, int and long must each one be at least as large as the one preceding it, with char being always one byte in size.

然而,.NET 对此进行了标准化,因此类型实际上被指定为 Int32Int64 等。在 C# 中,int 是一个System.Int32 的别名,始终为 32 位。 C# 语言规范中的 4.1.5 Integral Types 部分保证了这一点,其中指出:

The int type represents signed 32-bit integers with values between –2147483648 and 2147483647.

关于c# - C# 中的 int 是 32 位的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14900220/

相关文章:

c# - 如何使 Accordion 标题在页面加载时全部折叠?

c# - 代码级混淆器与程序集混淆器

c# - JavaScript 替换汉字

c# - 搜索 FileStream 然后使用 StreamReader 从那里读取

c# - 使用 ini/appconfig 文件或 sql server 文件来存储用户配置?

c# - 将 Azure AD B2C 登录用户链接到自定义数据库表用户

c# - 我可以相信一旦获得 HttpContext.Current.Cache 将永远有效吗?

c# - 带 OR 的 linq where 语句

c# - C# 中的 Promise 等价物

C# 基本操作的表现