SiteMapNodeCollection.Item[Int32] Proprietà

Definizione

Ottiene o imposta l'oggetto SiteMapNode in corrispondenza dell'indice specificato nell'insieme.

public:
 virtual property System::Web::SiteMapNode ^ default[int] { System::Web::SiteMapNode ^ get(int index); void set(int index, System::Web::SiteMapNode ^ value); };
public virtual System.Web.SiteMapNode this[int index] { get; set; }
member this.Item(int) : System.Web.SiteMapNode with get, set
Default Public Overridable Property Item(index As Integer) As SiteMapNode

Parametri

index
Int32

Indice dell'oggetto SiteMapNode da trovare.

Valore della proprietà

Oggetto SiteMapNode che rappresenta un elemento nell'oggetto SiteMapNodeCollection.

Eccezioni

index è minore di zero.

oppure

index è ottimo di Count.

Il valore fornito al setter è null.

Esempio

Nell'esempio di codice seguente viene illustrato come utilizzare l'indicizzatore Item[] per recuperare un SiteMapNode oggetto dalla SiteMapNodeCollection raccolta. In questo esempio, un SiteMapNode oggetto viene rimosso dalla relativa posizione nel secondo elemento della matrice interna usando il Remove metodo e viene aggiunto alla matrice con il Add metodo . Per inserire un SiteMapNode oggetto in corrispondenza di un indice specifico, anziché accodarlo alla fine della matrice, utilizzare il Insert metodo .


// Move a node from one spot in the list to another.
try {
    Response.Write("Original node order: <BR>");
    foreach (SiteMapNode node in nodes) {
        Response.Write( node.Title + "<BR>");
    }
    SiteMapNode aNode = nodes[1];

    Response.Write("Adding " + aNode.Title + " to the end of the collection.<BR>");
    nodes.Add(aNode);

    Response.Write("Removing " + aNode.Title + " at position 1. <BR>");
    nodes.Remove(nodes[1]);

    Response.Write("New node order: <BR>");
    foreach (SiteMapNode node in nodes) {
        Response.Write( node.Title + "<BR>");
    }
}
catch (NotSupportedException nse) {
    Response.Write("NotSupportedException caught.<BR>");
}

' Move a node from one spot in the list to another.
Try
    Response.Write("Original node order: <BR>")
    Dim node As SiteMapNode
    For Each node In nodes
        Response.Write( node.Title & "<BR>")
    Next

    Dim aNode As SiteMapNode = nodes(1)

    Response.Write("Adding " & aNode.Title & " to the end of the collection.<BR>")
    nodes.Add(aNode)

    Response.Write("Removing " & aNode.Title & " at position 1. <BR>")
    nodes.Remove(nodes(1))

    Response.Write("New node order: <BR>")

    For Each node In nodes
        Response.Write( node.Title & "<BR>")
    Next

Catch nse As NotSupportedException
    Response.Write("NotSupportedException caught.<BR>")
End Try

Commenti

È possibile utilizzare l'indicizzatore Item[] per scorrere il contenuto di una SiteMapNodeCollection raccolta o per sostituire l'oggetto SiteMapNode in corrispondenza di un indice specificato.

Si applica a

Vedi anche