Share via


WebPartZoneCollection.CopyTo(WebPartZoneBase[], Int32) 方法

定义

将集合复制到 WebPartZoneBase 对象的数组。

public:
 void CopyTo(cli::array <System::Web::UI::WebControls::WebParts::WebPartZoneBase ^> ^ array, int index);
public void CopyTo (System.Web.UI.WebControls.WebParts.WebPartZoneBase[] array, int index);
member this.CopyTo : System.Web.UI.WebControls.WebParts.WebPartZoneBase[] * int -> unit
Public Sub CopyTo (array As WebPartZoneBase(), index As Integer)

参数

array
WebPartZoneBase[]

用来包含被复制集合的 WebPartZoneBase 数组。

index
Int32

在数组中放置集合内容的起始点。

示例

下面的代码示例演示如何使用 CopyTo 方法。 示例的完整代码(包括用户控件、包含区域的页面和包含代码的分部类文件)可在类概述的 WebPartZoneCollection “示例”部分找到。

代码的以下部分演示了 方法的 CopyTo 用法。 若要执行代码,请在浏览器中加载页面,然后单击“ 数组中的区域名称 ”按钮。 区域集合将加载到数组中,所有区域 ID 都复制到标签中。

protected void Button3_Click(object sender, EventArgs e)
{
  Label1.Text = String.Empty;
  WebPartZoneBase[] zoneArray = new WebPartZoneBase[mgr.Zones.Count];
  mgr.Zones.CopyTo(zoneArray, 0);
  Label1.Text = zoneArray[2].ID;
  Label1.Text += ", " + zoneArray[1].ID;
  Label1.Text += ", " + zoneArray[0].ID;
}
Protected Sub Button3_Click(ByVal sender As Object, ByVal e As EventArgs)
  Label1.Text = String.Empty
  Dim zoneArray(mgr.Zones.Count) As WebPartZoneBase
  mgr.Zones.CopyTo(zoneArray, 0)
  Label1.Text = zoneArray(2).ID
  Label1.Text += ", " & zoneArray(1).ID
  Label1.Text += ", " & zoneArray(0).ID

End Sub

注解

CopyTo如果要创建可以包含集合中的WebPartZoneCollection区域的自定义数组、这些区域的子集或这些区域的超集,方法非常有用。

适用于

另请参阅