Unfortunately, VB.NET only supports readonly fields not readonly locals. VB.NET does not have anything like C++'s const
modifier to mark a variable as readonly.
Depending on the type of the variable, the Const
modifier might do the job but it doesn't mean the same thing as C++'s const
. In VB.NET, Const
is simply a variable whose value is known at compilation time, thus allowing the compiler to replace all usages of that variable in the source code with the value itself.
While the compiler will prevent you from modifying a Const
variable you are severely limited in your options for the types that you can mark as Const
since most types cannot provide a known value at compilation time.