Variables

Variables represent storage locations. Every variable has a type that determines what values can be stored in the variable. Fore.NET is a type-safe language and the compiler guarantees that values stored in variables are always of the appropriate type. The value of a variable can be changed through the assignment statement.

A variable must be definitely assigned before it can be used.

Variable Categories

Fore.NET language determines seven variable categories: static variables, instance variables, array elements, value parameters, reference parameters, output parameters, and local variables.

Default Values

The following variable categories are automatically initialized with default values:

The default value of a variable depends on its type and is determined as follows:

Variable References

A variable reference is an expression that is classified as a variable. A variable reference denotes a storage location that can be accessed both to get the current value and to modify it.

variable-reference:

expression

In C and C++, a variable reference is known as an l-value.

Example

Namespace UserApplicaton
//Variables available in entire assembly
Var
    GlobalValue: double;
    GlobalObject: object;
    
    Public Class UserObject
        //Static variable with default value
        Shared Options: integer = 10;
        //Instance variable
        ObjectValues: array Of double;
        
        Constructor UserObject();
        Begin
            ObjectValues := New Double[Options]
        End Constructor UserObject;
        
        //Parameter i is passed by value
        Public Property Item[i: integer]: double
            Get
            Begin
                //Get value of array element
                Return ObjectValues[i];
            End Get
            Set
            Begin
                //Assign value to an array element
                ObjectValues[i] := Value;
            End Set
        End Property Item;
        
        //The Summ parameter is passed by reference
        Sub SummElement(Var Summ: Double);
        //Local variables available only in the procedure
        Var
            d, d1: integer;
        Begin
            For Each d In ObjectValues Do
                d1 := d1 + d;
            End For;
            Summ := d1;
        End Sub;
    End Class UserObject;
End Namespace;

See also:

Description and Syntax Rules