MenuItemCollection.CopyTo Methode

Definitie

Hiermee kopieert u de inhoud van het huidige MenuItemCollection object.

Overloads

Name Description
CopyTo(Array, Int32)

Kopieert alle items van het MenuItemCollection object naar een compatibele eendimensionale Arraywaarde, beginnend bij de opgegeven index in de doelmatrix.

CopyTo(MenuItem[], Int32)

Kopieert alle items van het MenuItemCollection object naar een compatibele eendimensionale matrix van MenuItem objecten, te beginnen bij de opgegeven index in de doelmatrix.

CopyTo(Array, Int32)

Kopieert alle items van het MenuItemCollection object naar een compatibele eendimensionale Arraywaarde, beginnend bij de opgegeven index in de doelmatrix.

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)

Parameters

array
Array

Een op nul gebaseerde Array die de gekopieerde items van het huidige MenuItemCollectionontvangt.

index
Int32

De positie in de doelmatrix waarop de gekopieerde inhoud moet worden ontvangen.

Implementeringen

Uitzonderingen

array is geen matrix met MenuItem objecten.

Opmerkingen

Gebruik de CopyTo methode om de inhoud van het huidige MenuItemCollection object te kopiëren naar de opgegeven op nul gebaseerde System.Array. Items worden gekopieerd vanaf de opgegeven index van de doelmatrix. Met de System.Arraymatrixsyntaxis kunt u vervolgens toegang krijgen tot de items in het MenuItemCollection object.

Als alternatief kunt u ook de GetEnumerator methode gebruiken om een enumerator te maken die kan worden gebruikt voor toegang tot de items in de verzameling.

Zie ook

Van toepassing op

CopyTo(MenuItem[], Int32)

Kopieert alle items van het MenuItemCollection object naar een compatibele eendimensionale matrix van MenuItem objecten, te beginnen bij de opgegeven index in de doelmatrix.

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)

Parameters

array
MenuItem[]

Een op nul gebaseerde matrix met MenuItem objecten die de gekopieerde items van de huidige MenuItemCollectionontvangen.

index
Int32

De positie in de doelmatrix waarop de gekopieerde inhoud moet worden ontvangen.

Voorbeelden

In het volgende codevoorbeeld ziet u hoe u de CopyTo methode gebruikt om de items in een MenuItemCollection object te kopiëren naar een matrix met MenuItem objecten.


<%@ 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>

Opmerkingen

Gebruik de CopyTo methode om de inhoud van het huidige MenuItemCollection object te kopiëren naar de opgegeven matrix op basis van nul. Items worden gekopieerd vanaf de opgegeven index van de doelmatrix. Met de matrix kunt u vervolgens matrixsyntaxis gebruiken om toegang te krijgen tot de items in het MenuItemCollection object.

Als alternatief kunt u ook de GetEnumerator methode gebruiken om een enumerator te maken die kan worden gebruikt voor toegang tot de items in de verzameling.

Zie ook

Van toepassing op