C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Tip: Const values resolve faster than regular variables. They should be used when possible.
And: The const identifiers "_x" and "name" can be referenced in the same way as variable identifiers.
But: You cannot reassign a const. This provokes a compile-time error—the program will not compile.
VB.NET program that uses Const keyword
Module Module1
''' <summary>
''' Const can be Module or Class level.
''' </summary>
Const _x As Integer = 1000
Sub Main()
' Const can be Function or Sub level.
Const name As String = "Sam"
' Used as an argument.
Console.WriteLine(name)
Console.WriteLine(_x)
' Constant cannot be the target of an assignment.
'_x = 2000
End Sub
End Module
Output
Sam
1000
However: If you rewrite your VB.NET code to have Const values, but this increases code size, locality may be reduced.
And: This negates any performance wins. Code itself is data. Smaller code has an advantage.