ListItemCollection.CopyTo(Array, Int32) Method

Definition

Copies the items from the ListItemCollection to the specified Array, starting with the specified index.

C#
public void CopyTo(Array array, int index);

Parameters

array
Array

A zero-based Array that receives the copied items from the ListItemCollection.

index
Int32

The first index in the specified Array to receive the items.

Implements

Examples

C#
// Copy the items in the ListItemCollection to an array before 
// deleting them.     
ListItem[] myListItemArray = new ListItem[ListBox1.Items.Count];
ListBox1.Items.CopyTo(myListItemArray, 0);

// Delete all the items from the ListBox.
ListBox1.Items.Clear();
DeleteLabel.Text = "<b>All items in the ListBox were deleted successfully." 
    + "</b><br /><b>The deleted items are:";
String listResults="";
    foreach(ListItem myItem in myListItemArray)
    {
        listResults = listResults + myItem.Text + "<br />";
    }
ResultsLabel.Text = listResults;

Remarks

Use this method to copy the contents of the ListItemCollection into the specified System.Array, starting at the specified index.

Poznámka

The array parameter must be a zero-based System.Array.

Applies to

Produkt Verzie
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

See also