Variables

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

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

Variable Categories

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

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:

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;
        
        Public 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 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:

Fore.NET Language Guide | Constants