尝试将此转换为C#,但在设置为另一个常量时,它是否为某些十六进制值常量时会感到困惑。
Public Const STANDARD_RIGHTS_ALL = &H1F0000
Public Const SYNCHRONIZE = &H100000
Public Const KEY_CREATE_LINK = &H20
Public Const KEY_CREATE_SUB_KEY = &H4
Public Const KEY_ENUMERATE_SUB_KEYS = &H8
Public Const KEY_NOTIFY = &H10
Public Const KEY_QUERY_VALUE = &H1
Public Const KEY_SET_VALUE = &H2
Public Const KEY_READ = ((STANDARD_RIGHTS_READ Or _
KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS _
Or KEY_NOTIFY) And (Not SYNCHRONIZE))
C#?:
public const int KEY_READ = ((STANDARD_RIGHTS_READ || KEY_QUERY_VALUE || KEY_ENUMERATE_SUB_KEYS || KEY_NOTIFY) & (!SYNCHRONIZE));
答案 0 :(得分:5)
使用按位运算|,&和〜作为VB And
,Or
和Not
的等效项。
注意我将类型指定为uint
(无符号整数),以避免由于.NET(more information here)中int
类型的内部表示而产生的副作用。
public const uint READ_CONTROL = 0x20000;
public const uint STANDARD_RIGHTS_READ = READ_CONTROL;
public const uint STANDARD_RIGHTS_ALL = 0x1F0000;
public const uint SYNCHRONIZE = 0x100000;
public const uint KEY_CREATE_LINK = 0x20;
public const uint KEY_CREATE_SUB_KEY = 0x4;
public const uint KEY_ENUMERATE_SUB_KEYS = 0x8;
public const uint KEY_NOTIFY = 0x10;
public const uint KEY_QUERY_VALUE = 0x1;
public const uint KEY_SET_VALUE = 0x2;
public const uint KEY_READ = (
(STANDARD_RIGHTS_READ | KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS | KEY_NOTIFY)
& (~SYNCHRONIZE)
);