MenuItemCollection.CopyTo Metod
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Kopierar innehållet i det aktuella MenuItemCollection objektet.
Överlagringar
| Name | Description |
|---|---|
| CopyTo(Array, Int32) |
Kopierar alla objekt från MenuItemCollection objektet till en kompatibel endimensionell Array, med början vid det angivna indexet i målmatrisen. |
| CopyTo(MenuItem[], Int32) |
Kopierar alla objekt från MenuItemCollection objektet till en kompatibel endimensionell matris med MenuItem objekt, med början vid det angivna indexet i målmatrisen. |
CopyTo(Array, Int32)
Kopierar alla objekt från MenuItemCollection objektet till en kompatibel endimensionell Array, med början vid det angivna indexet i målmatrisen.
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)
Parametrar
- array
- Array
En nollbaserad Array som tar emot de kopierade objekten från den aktuella MenuItemCollection.
- index
- Int32
Positionen i målmatrisen där det kopierade innehållet ska börja tas emot.
Implementeringar
Undantag
array är inte en matris med MenuItem objekt.
Kommentarer
CopyTo Använd metoden för att kopiera innehållet i det aktuella MenuItemCollection objektet till den angivna nollbaserade System.Array. Objekt kopieras från och med det angivna indexet för målmatrisen. System.ArrayMed kan du sedan använda matrissyntax för att komma åt objekten MenuItemCollection i objektet.
Alternativt kan du också använda GetEnumerator metoden för att skapa en uppräknare som kan användas för att komma åt objekten i samlingen.
Se även
Gäller för
CopyTo(MenuItem[], Int32)
Kopierar alla objekt från MenuItemCollection objektet till en kompatibel endimensionell matris med MenuItem objekt, med början vid det angivna indexet i målmatrisen.
public:
void CopyTo(cli::array <System::Web::UI::WebControls::MenuItem ^> ^ array, int index);
public void CopyTo(System.Web.UI.WebControls.MenuItem[] array, int index);
member this.CopyTo : System.Web.UI.WebControls.MenuItem[] * int -> unit
Public Sub CopyTo (array As MenuItem(), index As Integer)
Parametrar
- array
- MenuItem[]
En nollbaserad matris med MenuItem objekt som tar emot de kopierade objekten från den aktuella MenuItemCollection.
- index
- Int32
Positionen i målmatrisen där det kopierade innehållet ska börja tas emot.
Exempel
Följande kodexempel visar hur du använder CopyTo metoden för att kopiera objekten i ett MenuItemCollection objekt till en matris med MenuItem objekt.
<%@ 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)
{
// Display the submenu items of the Music
// menu item.
// Retrieve the Music menu item.
MenuItem musicMenuItem = NavigationMenu.FindItem(@"Home");
// Declare an array of MenuItem objects.
MenuItem[] musicItemArray = new MenuItem[musicMenuItem.ChildItems.Count];
// Use the CopyTo method to copy the submenu items
// of the Music menu item into the array.
musicMenuItem.ChildItems.CopyTo(musicItemArray, 0);
// Display the menu items.
Message.Text = "The submenu items of the Home menu item are: <br/><br/>";
foreach (MenuItem item in musicItemArray)
{
Message.Text += item.Text + "<br />";
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>MenuItemCollection CopyTo Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>MenuItemCollection CopyTo Example</h3>
<asp:menu id="NavigationMenu"
orientation="Vertical"
target="_blank"
runat="server">
<items>
<asp:menuitem text="Home"
tooltip="Home">
<asp:menuitem text="Music"
tooltip="Music">
<asp:menuitem text="Classical"
tooltip="Classical"/>
<asp:menuitem text="Rock"
tooltip="Rock"/>
<asp:menuitem text="Jazz"
tooltip="Jazz"/>
</asp:menuitem>
<asp:menuitem text="Movies"
tooltip="Movies">
<asp:menuitem text="Action"
tooltip="Action"/>
<asp:menuitem text="Drama"
tooltip="Drama"/>
<asp:menuitem text="Musical"
tooltip="Musical"/>
</asp:menuitem>
</asp:menuitem>
</items>
</asp:menu>
<hr/>
<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)
' Display the submenu items of the Music
' menu item.
' Retrieve the Music menu item.
Dim musicMenuItem As MenuItem = NavigationMenu.FindItem("Home")
' Declare an array of MenuItem objects.
Dim musicItemArray(musicMenuItem.ChildItems.Count - 1) As MenuItem
' Use the CopyTo method to copy the submenu items
' of the Music menu item into the array.
musicMenuItem.ChildItems.CopyTo(musicItemArray, 0)
' Display the menu items.
Message.Text = "The submenu items of the Home menu item are: <br/><br/>"
Dim item As MenuItem
For Each item In musicItemArray
Message.Text &= item.Text & "<br />"
Next
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>MenuItemCollection CopyTo Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>MenuItemCollection CopyTo Example</h3>
<asp:menu id="NavigationMenu"
orientation="Vertical"
target="_blank"
runat="server">
<items>
<asp:menuitem text="Home"
tooltip="Home">
<asp:menuitem text="Music"
tooltip="Music">
<asp:menuitem text="Classical"
tooltip="Classical"/>
<asp:menuitem text="Rock"
tooltip="Rock"/>
<asp:menuitem text="Jazz"
tooltip="Jazz"/>
</asp:menuitem>
<asp:menuitem text="Movies"
tooltip="Movies">
<asp:menuitem text="Action"
tooltip="Action"/>
<asp:menuitem text="Drama"
tooltip="Drama"/>
<asp:menuitem text="Musical"
tooltip="Musical"/>
</asp:menuitem>
</asp:menuitem>
</items>
</asp:menu>
<hr/>
<asp:label id="Message"
runat="server"/>
</form>
</body>
</html>
Kommentarer
CopyTo Använd metoden för att kopiera innehållet i det aktuella MenuItemCollection objektet till den angivna nollbaserade matrisen. Objekt kopieras från och med det angivna indexet för målmatrisen. Med matrisen kan du sedan använda matrissyntax för att komma åt objekten MenuItemCollection i objektet.
Alternativt kan du också använda GetEnumerator metoden för att skapa en uppräknare som kan användas för att komma åt objekten i samlingen.