語言

SiteMapNodeCollection.Item[Int32] 屬性

定義

取得或設定 SiteMapNode 物件在集合中指定的索引位置。

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

參數

index
Int32

尋找的 SiteMapNode 索引。

屬性值

SiteMapNode A代表該元素中的SiteMapNodeCollection一個。

例外狀況

index 小於零。

-或-

index比 的 更好。Count

提供給設定器的值為 null。

範例

以下程式碼範例示範如何使用Item[]索引器從SiteMapNode集合中檢索SiteMapNodeCollection物件。 在此範例中, SiteMapNode 使用該 Remove 方法將物件從內部陣列的第二個元素移除,並附加到該陣列 Add 中。 若要在特定索引插入 SiteMapNode 物件,不要將其附加到陣列末尾,而是使用以下 Insert 方法。


// 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

備註

你可以使用 Item[] 索引器來遍歷集合內容 SiteMapNodeCollection ,或在指定索引處替換 SiteMapNode 物件。

適用於

另請參閱