int和System的区别是什么?Int16、系统。Int32和System。Int64,而不是它们的大小?


当前回答

以上这些人的回答基本正确。Int, int16, int32…根据数据存储容量的不同而有所不同。但这就是为什么编译器必须处理这些问题——它是为了解决潜在的2038年问题。点击链接了解更多信息。 https://en.wikipedia.org/wiki/Year_2038_problem

其他回答

没什么。两种类型之间的唯一区别是它们的大小(以及它们可以表示的值的范围)。

以上这些人的回答基本正确。Int, int16, int32…根据数据存储容量的不同而有所不同。但这就是为什么编译器必须处理这些问题——它是为了解决潜在的2038年问题。点击链接了解更多信息。 https://en.wikipedia.org/wiki/Year_2038_problem

int

它是c#中定义的基本数据类型。

它被映射到FCL类型的Int32。

它是一个值类型,表示System。Int32结构。

它是有符号的,长度为32位。

它具有最小值-2147483648和最大值+2147483647。

Int16

这是整柜型。

在c#中,short被映射为Int16。

它是一个值类型,表示System。Int16结构。

它带符号,长度为16位。

最小值为-32768,最大值为+32767。

Int32

这是整柜型。

在c#中,int被映射到Int32。

它是一个值类型,表示System。Int32结构。

它是有符号的,长度为32位。

它具有最小值-2147483648和最大值+2147483647。

Int64

这是整柜型。

在c#中,long被映射到Int64。

它是一个值类型,表示System。Int64结构。

它是有符号的,长度为64位。

它的最小值为-9,223,372,036,854,775,808,最大值为9,223,372,036,854,775,807。

根据Jeffrey Richter(.NET框架开发的贡献者之一)的书《CLR via c#》:

int是c#编译器允许的基本类型,而Int32是框架类库类型(适用于所有遵守CLS的语言)。事实上,int在编译时转换为Int32。

同时,

在c#中,长映射到系统。Int64,但是在不同的编程中 语言,long可以映射到Int16或Int32。事实上,c++ /CLI做到了 将long处理为Int32。 事实上,大多数(.NET)语言甚至不会将long视为关键字,也不会 编译使用它的代码。

我曾见过这位作者,以及许多关于. net的标准文献更喜欢FCL类型(例如。, Int32)到特定于语言的原语类型(即:, int),主要关注互操作性问题。

每种类型的整数具有不同的存储容量范围

   Type      Capacity

   Int16 -- (-32,768 to +32,767)

   Int32 -- (-2,147,483,648 to +2,147,483,647)

   Int64 -- (-9,223,372,036,854,775,808 to +9,223,372,036,854,775,807)

正如James Sutherland在他的回答中所述:

int and Int32 are indeed synonymous; int will be a little more familiar looking, Int32 makes the 32-bitness more explicit to those reading your code. I would be inclined to use int where I just need 'an integer', Int32 where the size is important (cryptographic code, structures) so future maintainers will know it's safe to enlarge an int if appropriate, but should take care changing Int32 variables in the same way. The resulting code will be identical: the difference is purely one of readability or code appearance.