3

I am aiming to create a private static readonly field in VB.NET.

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

This attempts to create a static property with only get access, but fails with the error:

'Static' is not valid on a member variable declaration.

In C#, I'd create this as follows:

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

How can I create and initialize a field in this similar manner in VB.NET?

spongebob
  • 8,370
  • 15
  • 50
  • 83
crush
  • 16,713
  • 9
  • 59
  • 100

1 Answers1

9
Private Shared ReadOnly

The VB equivalent to static members is Shared members.

crush
  • 16,713
  • 9
  • 59
  • 100
Dave Doknjas
  • 6,394
  • 1
  • 15
  • 28