Variables represent name=value entries in memory. You can think of variables as named objects that you define, for which you can assign values, that you can later use and modify.
A variable must be declared before you can use it. This initially sets the variable’s name and type in memory. The type determines what values can be stored in the variable ( ex. strings, integers, dates, etc. ).
// String
string productName;
// Integer
int totalItems;
// Boolean
bool hasImage;
// Date and Time
DateTime releaseDate;
' String
Dim productName As string
' Integer
Dim totalItems As Integer
' Boolean
Dim hasImage As Boolean
' Date and Time
Dim releaseDate As Date
// String
var productName : String;
// Integer
var totalItems : int;
// Boolean
var hasImage : bool;
// Date and Time
var releaseDate : Date; |
|
C# |
VB |
JScript |
NOTE: The type identifier must conform to the data types supported by the language. The .NET Framework is a type-safe environment, meaning each of the language compilers guarantee that values stored in variables are always of the correct type.
A variable can be assigned an initial value when it is declared.
// String
string productName = "Harry Potter and The Chamber of Secrets ( Widescreen Edition ) ";
// Integer
int totalItems = 5;
// Boolean
bool hasImage = false;
// Date and Time
DateTime releaseDate = DateTime.Now;
' String
Dim productName As string = "Harry Potter and The Chamber of Secrets ( Widescreen Edition ) "
' Integer
Dim totalItems As Integer = 5
' Boolean
Dim hasImage As Boolean = false
' Date and Time
Dim releaseDate As Date = Now
// String
var productName : String = "Harry Potter and The Chamber of Secrets ( Widescreen Edition ) ";
// Integer
var totalItems : int = 5;
// Boolean
var hasImage : bool = false;
// Date and Time
var releaseDate : Date = new Date ( ); |
|
C# |
VB |
JScript |
The value of a variable can be changed through assignment or through the use of operators appropriate to the language.
Show me