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

表示 SiteMapNode 中的元素的 SiteMapNodeCollection

例外

index 小于零。

  • 或 - index 大于 Count

提供给 setter 的值为 null

示例

下面的代码示例演示如何使用Item[]索引器从SiteMapNodeCollection集合中检索SiteMapNode对象。 在此示例中,使用该方法从内部数组Remove的第二个元素的位置中删除对象SiteMapNode,并使用该方法追加到数组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 指定索引处的对象。

适用于

另请参阅