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
一個以零為Array基礎的 ,會從 中接收複製的項目。RepeaterItemCollection
實作
範例
若想在完整範例中了解此程式碼,請參閱 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 的物件。