Welcome to the new DelphiDabbler Code Library Documentation.

This is a new site that's currently running on alpha code. There are going to be bugs. If you discover any, please report them on the site's issues page (GitHub account required). Thanks.

Warning: Many URLs are going to change. Refer to the README file to discover which library project's documentation has been completed.

UnShift<T> class method

Project: Array Utilities Unit

Unit: DelphiDabbler.Lib.ArrayUtils

Record: TArrayUtils

Applies to: ~>0.1

class procedure UnShift<T>(var A: TArray<T>; const AValue: T);
  static;

Description

Prepends a value to a given array

The length of the array is increased by one.

Parameters:

Example

This example prepends three elements to a previously empty string array.

procedure UnShift_Eg;
var
  A, Expected: TArray<string>;
begin
  A := TArray<string>.Create();

  TArrayUtils.UnShift<string>(A, 'foo');
  Expected := TArray<string>.Create('foo');
  Assert(TArrayUtils.Equal<string>(Expected, A, SameStr));

  TArrayUtils.UnShift<string>(A, 'bar');
  Expected := TArray<string>.Create('bar', 'foo');
  Assert(TArrayUtils.Equal<string>(Expected, A, SameStr));

  TArrayUtils.UnShift<string>(A, 'baz');
  Expected := TArray<string>.Create('baz', 'bar', 'foo' );
  Assert(TArrayUtils.Equal<string>(Expected, A, SameStr));
end;

See Also