4

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?

1 Answer 1

10
Private Shared ReadOnly

The VB equivalent to static members is Shared members.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.