| 文章: |
翻译自IVB Tip
VB .NET允许你在程序中建立数据类型的别名,以使你修改多个数据类型的声明变得更容易。考虑下面的代码:
Private Sub testthis2()
Dim test2 As System.Int16 = 32700
End Sub
Private Sub testthis1()
Dim test1 As System.Int16 = 32700
End Sub
但是,如果我们想使test1和test2变量存放更大的数据,我们不得不在两个地方修改数据类型。为了克服这个问题,我们现在建立System.Int16数据类型的别名,例如:
Imports MyChangingType = System.Int16
下面,我们使用新的数据类型修改test1和test2的类型:
Private Sub testthis2()
Dim test2 As MyChangingType = 32700
End Sub
Private Sub testthis1()
Dim test1 As MyChangingType = 32700
End Sub
现在,我们需要test1和test2保存更大的数值,我们所需要的只是修改Imports:
Imports MyChangingType = System.Int32
文章来源:IVB Tip。
附加关键字:编程, 源程序, programming, source code, Visual Basic, VB, 其他方面, 。
|