ListItemCollection.CopyTo(Array, Int32) ListItemCollection.CopyTo(Array, Int32) ListItemCollection.CopyTo(Array, Int32) Method

Definition

Kopiert die Elemente aus der ListItemCollection in das angegebene Array, wobei am angegebenen Index begonnen wird.Copies the items from the ListItemCollection to the specified Array, starting with the specified index.

public:
 virtual void CopyTo(Array ^ array, int index);
public void CopyTo (Array array, int index);
abstract member CopyTo : Array * int -> unit
override this.CopyTo : Array * int -> unit

Parameter

array
Array Array Array

Ein nullbasiertes Array, das die kopierten Elemente aus der ListItemCollection empfängt.A zero-based Array that receives the copied items from the ListItemCollection.

index
Int32 Int32 Int32

Der erste Index im angegebenen Array, an dem die Elemente abgelegt werden.The first index in the specified Array to receive the items.

Implementiert

Beispiele

// 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;
' Copy the items in the ListListBox1.Items to an array before 
' deleting them.     
Dim myListItemArray(ListBox1.Items.Count - 1) As ListItem
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:"
Dim listResults As [String] = ""
Dim myItem2 As ListItem
For Each myItem2 In myListItemArray
    listResults = listResults & myItem2.Text & "<br />"
Next myItem2
ResultsLabel.Text = listResults

Hinweise

Verwenden Sie diese Methode, um den Inhalt von ListItemCollection in den angegebenen System.Arrayzu kopieren, beginnend am angegebenen Index.Use this method to copy the contents of the ListItemCollection into the specified System.Array, starting at the specified index.

Hinweis

Der array -Parameter muss NULL basiert System.Arraysein.The array parameter must be a zero-based System.Array.

Gilt für:

Siehe auch