[翻译]  Is there any difference between Integer and Int32 in VB.NET?

[CHINESE]  VB.NET中的Integer和Int32有什么区别吗?


In VB.NET, is there any difference between Integer and Int32?

在VB.NET中,Integer和Int32之间有什么区别吗?

If yes, please explain.

如果是,请解释。

1 个解决方案

#1


31  

Functionally, there is no difference between the types Integer and System.Int32. In VB.NET Integer is just an alias for the System.Int32 type.

从功能上讲,Integer和System.Int32之间没有区别。在VB.NET中,Integer只是System.Int32类型的别名。

The identifiers Int32 and Integer are not completely equal though. Integer is always an alias for System.Int32 and is understood by the compiler. Int32 though is not special cased in the compiler and goes through normal name resolution like any other type. So it's possible for Int32 to bind to a different type in certain cases. This is very rare though; no one should be defining their own Int32 type.

但标识符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 local1 and local2 are actually different types, because Int32 binds to the user defined type over System.Int32.

在这种情况下,local1和local2实际上是不同的类型,因为Int32通过System.Int32绑定到用户定义的类型。


注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
© 2014-2018 ITdaan.com 粤ICP备14056181号