Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the equivalent of private static readonly field in VB.net?

Tags:

vb.net

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?

like image 766
crush Avatar asked Oct 17 '25 18:10

crush


1 Answers

Private Shared ReadOnly

The VB equivalent to static members is Shared members.

like image 93
Dave Doknjas Avatar answered Oct 20 '25 08:10

Dave Doknjas