Add(Value: Double): Integer;
Add(Value: System.Double): System.Int32;
Value. New array element.
The Add method adds a new element to array.
The module containing the example should have link to the Visualizators system assembly. This procedure should be called from the Main entry point.
Create a new array of real numbers with double precision and add elements to it. Insert a new element into the position with index 3 and remove the element from the position with index 2. Display the sum of all array elements. Then clear the array and display its size.
Sub UserProc;
Var
Array: IVZDoubleArray; // Real numbers array
i: Integer; // Counter
Sum: Double; // Sum of elements
Begin
// Create new array and add elements to it
Array := New VZDoubleArray.Create;
0Array.Add(50.535648);
1 Array.Add(60.145664);
2 Array.Add(70.445645);
// Insert new element to position with index 2
Array.InsertAt(2, 80.447321);
// Remove element from position with index 0
Array.Remove(0);
// Display element value in position with index 2
Debug.WriteLine("Item in position with index 2: " + Array.Item(2).ToString);
// Display sum of all array elements
Sum := 0;
For i := 0 To Array.Count - 1 Do
Sum := Sum + Array.Item(i);
End For;
Debug.WriteLine("Sum of all array elements: " + Sum.ToString);
// Clear array
Array.Clear;
// Output array size
Debug.WriteLine("Array size after clearing: " + Array.Count.ToString);
End Sub UserProc;
After executing the example, the development environment console window shows value of the array element in position with index 2, the sum of all array elements and array size after it is cleared:
Item in position with index 2: 70.445644999999999
Sum of all array elements: 211.03863000000001
Array size after clearing: 0
The selected procedure is the Main entry point in the Program module of the .NET assembly. The Visualizators assembly should be imported to this module from the Prognoz.Platform.Interop system assembly.
Create a new array of real numbers with double precision and add elements to it. Insert a new item into the position with index 3 and remove the element from the position with index 2. Display the sum of all array elements. Then clear the array and display its size:
Public Shared Sub Main(Params: StartParams);
Var
Array: IVZDoubleArray; // Real numbers array
i: Integer; // Counter
Sum: Double; // Sum of elements
Begin
// Create new array and add elements to it
Array := New VZDoubleArray.Create();
Array.Add(50.535648);
Array.Add(60.145664);
Array.Add(70.445645);
// Insert new element to position with index 2
Array.InsertAt(2, 80.447321);
// Remove element from position with index 0
Array.Remove(0);
// Display element value in position with index 2
System.Diagnostics.Debug.WriteLine("Item in position with index 2: " + Array.Item[2].ToString());
// Display sum of all array elements
Sum := 0;
For i := 0 To Array.Count - 1 Do
Sum := Sum + Array.Item[i];
End For;
System.Diagnostics.Debug.WriteLine("Sum of all array elements: " + Sum.ToString());
// Clear array
Array.Clear();
// Output array size
System.Diagnostics.Debug.WriteLine("Array size after clearing: " + Array.Count.ToString());
End Sub Main;
The result of the executed example is the same as that, executed for Fore language.
See also: