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

定义

将集合复制到 WebPartZoneBase 对象的数组。Copies the collection to an array of WebPartZoneBase objects.

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 数组。A WebPartZoneBase array to contain the copied collection.

index
Int32

在数组中放置集合内容的起始点。The starting point in the array at which to place the collection contents.

示例

下面的代码示例演示CopyTo方法的用法。The following code example demonstrates the use of the CopyTo method. WebPartZoneCollection类概述的 "示例" 部分中提供了此示例的完整代码, 包括用户控件、包含这些区域的页面以及包含代码的分部类文件。The complete code for the example, including a user control, a page containing the zones, and a partial class file that contains the code, is found in the Example section of the WebPartZoneCollection class overview.

下面的代码部分演示CopyTo方法的用法。The following section of the code demonstrates usage of the CopyTo method. 若要执行该代码, 请在浏览器中加载此页, 然后单击 "数组" 按钮中的区域名称To execute the code, load the page in a browser, and click the Zone Names from Array button. 区域的集合被加载到数组中, 所有区域 Id 都复制到一个标签中。The collection of zones is loaded into an array, and all zone IDs are copied into a label.

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

注解

如果要创建一个自定义数组, 该数组可以包含WebPartZoneCollection集合中的区域、这些区域的子集或这些区域的超集, 则方法非常有用。CopyToThe CopyTo method is useful when you want to create a custom array that can contain the zones in the WebPartZoneCollection collection, a subset of those zones, or a superset of those zones.

适用于

另请参阅