VB.NET 中的 Integer 和 Int32 之间有什么区别吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15287742/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there any difference between Integer and Int32 in VB.NET?
提问by Vikram
In VB.NET, is there any difference between Integerand Int32?
在 VB.NET 中,Integer和之间有什么区别Int32吗?
If yes, please explain.
如果是,请解释。
回答by JaredPar
Functionally, there is no difference between the types Integerand System.Int32. In VB.NET Integeris just an alias for the System.Int32type.
在功能上,类型Integer和之间没有区别System.Int32。在 VB.NETInteger中只是System.Int32类型的别名。
The identifiers Int32and Integerare not completely equal though. Integeris always an alias for System.Int32and is understood by the compiler. Int32though is not special cased in the compiler and goes through normal name resolution like any other type. So it's possible for Int32to bind to a different type in certain cases. This is very rare though; no one should be defining their own Int32type.
标识符Int32和Integer并不完全相等。 Integer始终System.Int32是编译器的别名并被编译器理解。Int32虽然在编译器中不是特殊情况,并且像任何其他类型一样通过正常的名称解析。所以Int32在某些情况下可以绑定到不同的类型。不过,这种情况非常罕见;没有人应该定义自己的Int32类型。
Here is a concrete repro which demonstrates the difference.
这是一个具体的再现,它展示了差异。
Class Int32
End Class
Module Module1
Sub Main()
Dim local1 As Integer = Nothing
Dim local2 As Int32 = Nothing
local1 = local2 ' Error!!!
End Sub
End Module
In this case local1and local2are actually different types, because Int32binds to the user defined type over System.Int32.
在这种情况下local1和local2实际上是不同的类型,因为Int32绑定到用户定义的类型 over System.Int32。

