Is it possible to declare a dynamic constant in VB.NET?

I am trying to save a timestamp in a constant at the beginning of the program that will be used throughout the program. For example:

Const TIME_STAMP = Format(Now(), "hhmm")

However, this code generates a compiler error - "Constant expression required." Does this mean that all constants in VB.NET should contain flat, static, hard-coded data? I know that you can initialize a constant with a dynamic value in other languages ​​(for example, Java) - what makes it a constant is that after the initial assignment you can no longer change it. Is there an equivalent in VB.NET?

+5
source share
3 answers

, , - readonly. .

ReadOnly TIME_STAMP As String = Format(Now(), "hhmm")
+6

Shared Readonly Const - . Shared Readonly - .

Java Const - , static final .

+7

. , ​​ , , ReadOnly...

Public Shared ReadOnly TIME_STAMP = Format(Now(), "hhmm")

, "Shared" .

+1

All Articles