ListItemCollection.CopyTo(Array, Int32) 方法

定义

ListItemCollection 中的项复制到指定的 Array 中,从指定的索引开始。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
Public Sub CopyTo (array As Array, index As Integer)

参数

array
Array

一个从零开始的 Array,它接收 ListItemCollection 的复制项。A zero-based Array that receives the copied items from the ListItemCollection.

index
Int32

指定 Array 中接收项的第一个索引。The first index in the specified Array to receive the items.

实现

示例

// 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

注解

使用此方法可 ListItemCollection System.Array 从指定索引处开始,将的内容复制到指定的中。Use this method to copy the contents of the ListItemCollection into the specified System.Array, starting at the specified index.

备注

array参数必须是从零开始的 System.ArrayThe array parameter must be a zero-based System.Array.

适用于

另请参阅