ICollection.CopyTo

Syntax

CopyTo(Arr: Array; Index: Integer);

Parameters

Arr. Array, to which collection elements must be copied.

Index. Index of position in the array, from which elements are inserted.

Description

The CopyTo method copies collection to the Arr array.

Comments

Elements are inserted starting from the Index position. The specified array must be initialized before. If size of the specified array is less than the number of collection elements, not all data is copied.

Example

Sub UserProc;
Var
    StrL: IStringList;
    Arr: Array;
    i: Integer;
    v: Variant;
Begin
    StrL := New StringList.Create;
    For i := 0 To Math.RandBetweenI(010Do
        StrL.Add(Char.Chr(Math.RandBetweenI(6590)));
    End For;
    Arr := New Variant[Strl.Count];
    Strl.CopyTo(Arr, 0);
    //View values in the obtained array
    For Each v In Arr Do
        Debug.WriteLine(v);
    End For;
End Sub UserProc;

On executing the example all elements from the StrL string array are copied to the Arr array.

See also:

ICollection | Arrays