A constant is just like a variable (it holds a value) but, unlike a variable, you cannot change the value of a constant.
VB.Net Constants
In VB.Net, you define constants with the Const keyword.
All constants are part of a class (no global constants) but you can make a constant public and have access to it using ClassName.ConstantName so long as you have added the class to the project. This works even without creating the class as if the public constants were static, but you cannot use the Shared keyword.
Constants must be of an integral type (sbyte, byte, short, ushort, int, uint, long, ulong, char, float, double, decimal, bool, or string), an enumeration, or a reference to null.
Syntax Example:
Public Class Convert Inherits System.Object
Public Const kName As String = "Mike"
Private Const kPI Double = 3.1459
//Declare two or more on same line too: Const kFeetToMeter = 3.2808, kMeterToFeet = 0.3048 End Class
The following are practice certification questions with answers highlighted. These questions were prepared by Mike Prestwood and are intended to stress an important aspect of this KB post. All our practice questions are intended to prepare you generally for passing any certification test as well as prepare you for professional work.