The constant is also a variable, but the value of the constant must be fixed. The constant value is not going to change during its lifetime. Once we define with the one value, that value should apply to the entire program.Simply, we can say that Constant is a Fixed Value. We can also call constant as "literal".The Constant may be any of the following types. The type of the constant value depends on the user requirement.The Constant value should be declared with the keyword called "Const".
Integer Constant
Floating Constant
Double Constant
Character Constant
String Literal
Conceptual
figure
Following is a conceptual figure which describes the root of constants.
[vbnet]public Const a [As integer]=100[/vbnet]
See the above example.Here, public is the access specifier, a is the Constant name, integer is the datatype, and the 100 is the initialized value which is going to be fixed.
[vbnet]
Module ConstantExample
Sub Main()
Const PI = 3.14149
Dim r, area As integer
r = 7
area = PI * r* r
Console.WriteLine("Area = " & Str(area))
Console.ReadKey()
End Sub
End Module
[/vbnet]
Output:
When you execute the above code, then you will get the following output.
Summary
Points
Enum is a combination of constants.
Once developer declare the constants then it can not be changed but it will be used to the whole program.
Display and print both are the constants available in VB.Net.