C# 在 VB.NET 中声明一个十六进制常量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10240587/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 13:01:03  来源:igfitidea点击:

Declaring a hex constant in VB.NET

c#vb.nethexconst

提问by Ali

How can I convert the following C# hexadecimal into a VB.NEThexadecimal?

如何将以下 C# 十六进制转换为VB.NET十六进制?

private const UInt32 temp = 0xE6359A60;

I tried the following, but it doesn't work.

我尝试了以下方法,但不起作用。

Public Const temp As System.UInt32 = 0xE6359A60

采纳答案by Niranjan Singh

C# uses 0xand VB.NETuses &Has the prefix to specify hexadecimal numbers.try this.

C# 使用0xVB.NET使用&H作为前缀来指定十六进制数字。尝试这个。

Public Const temp As Integer = &HE6359A60

Sub Main

End Sub

And it could be as Uint also:

它也可以是 Uint:

Public Const temp As UInt32 = &HE6359A60UI

Sub Main

End Sub

Check MSDN's Type Characters (Visual Basic)documentation for defining hexadecimal and octal literals:

检查 MSDN 的类型字符 (Visual Basic)文档以定义十六进制和八进制文字:

The compiler normally construes an integer literal to be in the decimal (base 10) number system. You can force an integer literal to be hexadecimal (base 16)with the &H prefix, and you can force it to be octal (base 8)with the &O prefix. The digits that follow the prefix must be appropriate for the number system.

编译器通常将整数文字解释为十进制(基数为 10)的数字系统。您可以使用&H 前缀强制整数文字为十六进制(16 为底),也可以使用&O 前缀将其强制为八进制(以 8底)。前缀后面的数字必须适用于数字系统。

References:

参考:

回答by Alex

Public Const temp As Integer = &H6359A60

Prefix it with &H

前缀为 &H