【问题标题】:What is the equivalent of private static readonly field in VB.net?VB.net 中私有静态只读字段的等价物是什么?
【发布时间】:2015-03-13 23:19:09
【问题描述】:

我的目标是在 VB.NET 中创建一个私有静态只读字段

Public Class MyClass
    Private Static ReadOnly someField As Regex = New Regex("somePattern")
End Class

这试图创建一个只有 get 访问权限的静态属性,但失败并出现错误:

“静态”在成员变量声明中无效。

在 C# 中,我将按如下方式创建:

public class MyClass
{
    private static readonly Regex someField = new Regex("somePattern");
}

如何在 VB.NET 中以类似的方式创建和初始化字段?

【问题讨论】:

    标签: vb.net


    【解决方案1】:
    Private Shared ReadOnly
    

    相当于static members 的VB 是Shared members。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-30
      • 1970-01-01
      • 2012-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-23
      相关资源
      最近更新 更多