WizardStepCollection.CopyTo(WizardStepBase[], Int32) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
從目標陣列的指定索引開始,複製 WizardStepCollection 集合的所有項目至 WizardStepBase 物件的相容一維陣列。
public:
void CopyTo(cli::array <System::Web::UI::WebControls::WizardStepBase ^> ^ array, int index);
public void CopyTo (System.Web.UI.WebControls.WizardStepBase[] array, int index);
member this.CopyTo : System.Web.UI.WebControls.WizardStepBase[] * int -> unit
Public Sub CopyTo (array As WizardStepBase(), index As Integer)
參數
- array
- WizardStepBase[]
WizardStepBase 物件之以零起始的陣列,接收複製自集合之項目。
- index
- Int32
目標陣列中開始接收複製項目的位置。
範例
下列範例示範如何使用 CopyTo 方法,將 物件從集合複製到 WizardStepBase 陣列。 接著會逐一查看陣列,以顯示 ID 每個 WizardStepBase衍生物件的屬性。 請注意,在範例中, WizardSteps 控件的 Wizard 屬性是 類別 WizardStepCollection 的實例。
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
void Page_Load(Object sender, EventArgs e)
{
// Declare an array of WizardStepBase objects.
WizardStepBase[] stepArray = new WizardStepBase[Wizard1.WizardSteps.Count];
// Use the CopyTo method to copy the WizardStep items
// of the Wizard control into the array.
Wizard1.WizardSteps.CopyTo(stepArray, 0);
// Display the WizardStep items.
Message.Text = "The WizardStepBase items of the Wizard1 control are: <br/><br/>";
for (int i = 0; i < stepArray.Length; i++)
{
Message.Text += stepArray[i].ID + "<br />";
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ASP.NET Example</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Wizard id="Wizard1"
runat="server" >
<WizardSteps>
<asp:WizardStep id="WizardStep1"
runat="server"
title="Step 1">
</asp:WizardStep>
<asp:WizardStep id="WizardStep2"
runat="server"
title="Step 2">
</asp:WizardStep>
<asp:WizardStep id="WizardStep3"
runat="server"
title="Step 3">
</asp:WizardStep>
</WizardSteps>
<HeaderTemplate>
<b>WizardStepCollection CopyTo Example</b>
</HeaderTemplate>
</asp:Wizard>
<asp:label id="Message"
runat="server"/>
</form>
</body>
</html>
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
' Declare an array of WizardStepBase objects.
Dim stepArray(Wizard1.WizardSteps.Count - 1) As WizardStep
' Use the CopyTo method to copy the WizardStep items
' of the Wizard control into the array.
Wizard1.WizardSteps.CopyTo(stepArray, 0)
' Display the WizardStep items.
Message.Text = "The WizardStepBase items of the Wizard1 control are: <br/><br/>"
For i As Integer = 0 To stepArray.Length - 1
Message.Text &= stepArray(i).ID & "<br />"
Next
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ASP.NET Example</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Wizard id="Wizard1"
runat="server" >
<WizardSteps>
<asp:WizardStep id="WizardStep1"
runat="server"
title="Step 1">
</asp:WizardStep>
<asp:WizardStep id="WizardStep2"
runat="server"
title="Step 2">
</asp:WizardStep>
<asp:WizardStep id="WizardStep3"
runat="server"
title="Step 3">
</asp:WizardStep>
</WizardSteps>
<HeaderTemplate>
<b>WizardStepCollection CopyTo Example</b>
</HeaderTemplate>
</asp:Wizard>
<asp:label id="Message"
runat="server"/>
</form>
</body>
</html>
備註
CopyTo使用方法,將集合的內容複製到指定的以零起始的陣列中。 專案會從目標陣列的指定索引開始複製。 項目在陣列中之後,您可以使用數位語法來存取集合中的 WizardStepCollection 專案。
或者,您也可以使用 GetEnumerator 方法來建立列舉值,以用來存取集合中的專案。