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


当前回答

它们告诉我们什么大小可以存储在一个整数变量中。为了记住大小,你可以这样想:-)2个啤酒(2字节),4个啤酒(4字节)或8个啤酒(8字节)。

Int16:- 2 beers/bytes = 16bit = 2^16 = 65536 = 65536/2 = -32768 to 32767 Int32:- 4 beers/bytes = 32 bit = 2^32 = 4294967296 = 4294967296/2 = -2147483648到2147483647 Int64:- 8 beers/bytes = 64 bit = 2^64 = 18446744073709551616 = 18446744073709551616/2 = -9223372036854775808到9223372036854775807

总之,你不能在int16中存储超过32767的值,超过 int32中的值大于9223372036854775807的值 int64。

为了理解上面的计算,你可以看看这个视频int16 vs int32 vs int64

其他回答

Int=Int32——>原始长类型 Int16——>原始int Int64—>在64位系统之后提供新的数据类型 "int"仅用于向后兼容。我们应该使用新的int类型使我们的程序更精确。 --------------- 我注意到的另一件事是,没有类似于Int16、Int32和Int64的名为Int的类。所有有用的函数,如TryParse for integer,都来自Int32.TryParse。

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

   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.

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。

它们告诉我们什么大小可以存储在一个整数变量中。为了记住大小,你可以这样想:-)2个啤酒(2字节),4个啤酒(4字节)或8个啤酒(8字节)。

Int16:- 2 beers/bytes = 16bit = 2^16 = 65536 = 65536/2 = -32768 to 32767 Int32:- 4 beers/bytes = 32 bit = 2^32 = 4294967296 = 4294967296/2 = -2147483648到2147483647 Int64:- 8 beers/bytes = 64 bit = 2^64 = 18446744073709551616 = 18446744073709551616/2 = -9223372036854775808到9223372036854775807

总之,你不能在int16中存储超过32767的值,超过 int32中的值大于9223372036854775807的值 int64。

为了理解上面的计算,你可以看看这个视频int16 vs int32 vs int64

编辑:这对c#来说并不完全正确,我在回答这个问题时漏掉了一个标签——如果有更具体的c#答案,请投票给它!


它们都代表不同大小的整数。

然而,有一个非常非常微小的区别。

Int16、int32和int64的大小都是固定的。

int型的大小取决于你所编译的体系结构——C规范只将int型定义为大于或等于short型,但实际上它是你的目标处理器的宽度,可能是32位,但你应该知道它可能不是。