假设我有一些相互依赖的常量,我决定将它们放在一个容器中,而不是将其作为类中的单个常量。
我本想为该作用域使用Structure,但编译器强制我为该结构声明一个私有成员。
  ' Compile error: at least one private member is needed.
  Private Structure BandSizes 
    Const BandHeight As Short = HourHeight + 20
    Const HourHeight As Short = HalfHourHeight + 20
    Const HalfHourHeight As Short = LineHeight + PictureHeight + 20
    Const PictureHeight As Short = 20
    Const LineHeight As Short = StopHeight + 10
    Const LineWidth As Short = 50
    Const StopHeight As Short = 30
  End Structure由于我只有几个整数常量,我应该创建一个共享(静态)类吗?
平台: VB.NET (.NET 2)
发布于 2010-06-29 18:40:06
由于它是VB.NET,如果它们是真正的全局常量,并且它们的名称本身就足够了,那么您还可以创建一个模块来保存它们。
此外,请注意,如果从外部程序集访问这些常量,则这些常量的值可能会发生更改。因此,如果它们是公共的,并放在一个类库中,例如,将它们作为ReadOnly而不是常量可能会更好。
https://stackoverflow.com/questions/3139787
复制相似问题