我是C#程序员,但我正在将一些代码从C#转换为VB.NET.在C#中,我可以简单地使用(int)blah.getValue(),其中getValue()返回Integer?
DirectCast()在VB.NET中做一个不起作用,说Integer?无法转换为Integer.
想法?
使用value属性获取实际的整数值.
Dim intNullable As Integer?
If intNullable.HasValue Then
Return intNullable.Value
End If
Run Code Online (Sandbox Code Playgroud)
整数?是可以为空的类型,因此您可能必须将其转换为可以为空的Integer.
你想使用像这样的CType函数,'Integer'或'Integer?' 根据您的情况而定
Val = CType(Source,Integer?)
Run Code Online (Sandbox Code Playgroud)