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?
Private Shared ReadOnly
The VB equivalent to static
members is Shared
members.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With