如何在VB中定义64位常量?

Nor*_*rmD 2 vb.net constants

在Visual Basic中

Friend Const xxx As UInt64 = 400 * 365 * 24 * 60 * 60 ''// Number of secs in 400 years
Run Code Online (Sandbox Code Playgroud)

这失败了,错误

constant expression not representable in type integer
Run Code Online (Sandbox Code Playgroud)

问题是400*365*24*60*60大于2 ^ 32

我原以为通过将常量声明为UInt64,可以为其分配64位值

Joe*_*orn 7

除了每年略多于365天(你需要增加97个闰日)的事实之外,每个乘以组成常量的值都是整数文字,因此在你将它们分配给UInt64之前,它是全部在整数空间内完成.试试这个:

Friend Const xxx As UInt64 = 400UL * 365UL * 24UL * 60UL * 60UL
Run Code Online (Sandbox Code Playgroud)