c#代码转vb代码
public static bool Lit = false;
static ValueHelper()
{
unsafe
{
int test = 1;
Lit = (*(byte*)(&test)) == (byte)1;
}
}
上面这段代码转成vb.net应该怎么写,尝试用转换器无法编译.
Lit = (CType(AddressOf test, Pointer(Of Byte)).Target) = CByte(1)
------解决方案--------------------好像VB.NET不支持unsafe代码吧
------解决方案--------------------
这样是通不过的,语法错误。
Friend Class Program
' Methods
Private Shared Sub Main(ByVal args As String())
End Sub
Private Shared Sub ValueHelper()
Dim test As Integer = 1
Program.Lit = (DirectCast(AddressOf test, Byte*) = 1)
End Sub
' Fields
Public Shared Lit As Boolean = False
End Class
不过这个Lit = (*(byte*)(&test)) == (byte)1;到底是什么用,取地址又根据地址取值,那和直接test==1有什么区别?