Project: Array Utilities Unit
Unit: DelphiDabbler.Lib.ArrayUtils
Record: TArrayUtils
Applies to: ~>0.1
class procedure Push<T>(var A: TArray<T>; const AValue: T);
static;Appends a value to a given array
The length of the array is increased by one.
Parameters:
-
A - Array to which the element is to be added. The array is updated in place when the element is added.
-
AValue - The element to be added to the array.
This example appends three elements to a previously empty string array.
procedure Push_Eg;
var
A, Expected: TArray<string>;
begin
A := TArray<string>.Create();
TArrayUtils.Push<string>(A, 'foo');
Expected := TArray<string>.Create('foo');
Assert(TArrayUtils.Equal<string>(Expected, A, SameStr));
TArrayUtils.Push<string>(A, 'bar');
Expected := TArray<string>.Create('foo', 'bar');
Assert(TArrayUtils.Equal<string>(Expected, A, SameStr));
TArrayUtils.Push<string>(A, 'baz');
Expected := TArray<string>.Create('foo', 'bar', 'baz');
Assert(TArrayUtils.Equal<string>(Expected, A, SameStr));
end;