In VB.NET, is there any difference between Integer
and Int32
?
If yes, please explain.
In VB.NET, is there any difference between Integer
and Int32
?
If yes, please explain.
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.
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.
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
.
int
and Int32
–
Rowdyish Class [Int32]
. Thanks –
Tunicate Int32
isn't a keyword in Vb.Net although many believe it to be. It's just another name that's interpreted like anything else –
Rowdyish Integer
and System.Int32
, then the answer would be no. Generated code should specify the namespace to prevent this problem from ever happening. –
Tami © 2022 - 2024 — McMap. All rights reserved.