Purpose | Variables and arrays are declared to store values locally within methods, programs or within classes. The possible datatypes of the variables and arrays can be found by clicking here. | |||||||||||
Format |
{datatype} {variable};
{datatype} {variable} = {value};
{datatype} {array name and size};
{datatype} {array name and size} = {elements};
{datatype} |
the datatype of the variable or array being defined. |
{variable} |
the name of the variable being defined. |
{value} |
the value being assigned to the variable being defined. |
{array name and size} |
the name of the array followed by the number of elements bounded by square brackets. |
{elements} |
a comma-separated list of values for the elements of the array being defined. |
|
|
Example #1 |
string sRet; int i; Defines a string variable called sRet and an integer variable called i. |
|||||||||||
Example #2 |
string sRet = "Hello"; int i = 7; Defines a string variable called sRet whose value is Hello and an integer variable called i whose value is 7. |