語言

RepeaterItemCollection.CopyTo(Array, Int32) 方法

定義

從該RepeaterItemCollection物件中指定的索引Array開始,將所有項目複製到指定Array物件。

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基礎的 ,會從 中接收複製的項目。RepeaterItemCollection

index
Int32

在指定 Array 位置中第一個接收複製內容。

實作

範例

若想在完整範例中了解此程式碼,請參閱 RepeaterItemCollection 課程主題。

      void CopyTo_Clicked(Object Sender, EventArgs e)
      {
labelDisplay.Text = "Invoking CopyTo method.<br />";
labelDisplay.Text += "The Items collection contains: <br />";

// Display the elements of the RepeaterItemCollection using the CopyTo method.
RepeaterItemCollection  myItemCollection = myRepeater.Items;
RepeaterItem[] myItemArray = new RepeaterItem[myItemCollection.Count];
myItemCollection.CopyTo(myItemArray,0);
for(int index=0;index < myItemArray.Length;index++)
{
   RepeaterItem myItem = (RepeaterItem)myItemArray.GetValue(index);
   labelDisplay.Text += ((DataBoundLiteralControl)
      myItem.Controls[0]).Text + "<br />";
}
      }
Sub CopyTo_Clicked(Sender As Object, e As EventArgs)
   labelDisplay.Text = "Invoking CopyTo method.<br />"
   labelDisplay.Text += "The Items collection contains: <br />"
   
   ' Display the elements of the RepeaterItemCollection using the CopyTo method.
   Dim myItemCollection As RepeaterItemCollection = myRepeater.Items
   Dim myItemArray(myItemCollection.Count-1) As RepeaterItem
   myItemCollection.CopyTo(myItemArray, 0)
   Dim index As Integer
   For index = 0 To myItemArray.Length - 1
      Dim myItem As RepeaterItem = CType(myItemArray.GetValue(index), RepeaterItem)
      labelDisplay.Text += CType(myItem.Controls(0), DataBoundLiteralControl).Text + "<br />"
   Next index
End Sub 'CopyTo_Clicked

備註

使用此方法將 的內容 RepeaterItemCollection 從指定的索引開始複製到指定 System.Array 物件中。

Note

參數 array 必須是以零為基礎 System.Array 的物件。

適用於

另請參閱