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 对象中。
注释
参数 array 必须是从 System.Array 零开始的对象。