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


当前回答

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

其他回答

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

   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.

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


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

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

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

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

Int和int32是同一个(32位整数) Int16是短int(2字节或16位) Int64是长数据类型(8字节或64位)

他们确实是同义的,但是我发现他们之间的小区别,

1)创建enum时不能使用Int32

enum Test : Int32
{ XXX = 1   // gives you compilation error
}

enum Test : int
{ XXX = 1   // Works fine
}

2) Int32属于System声明。如果你不使用。在系统中,你会得到编译错误,但在int中不会

唯一真正的区别是大小。这里所有的int类型都是带符号的整型值,大小不同

Int16: 2字节 Int32和int: 4字节 Int64: 8字节

Int64和其他的有一个小的区别。在32位平台上,分配给Int64存储位置不保证是原子的。对于所有其他类型都是保证的。