RepeaterItemCollection.CopyTo(Array, Int32) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
將全部項目從 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
從 RepeaterItemCollection 接收複製項目的以零為起始的 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 物件。
注意
參數 array
必須是以零起始 System.Array 的物件。