言語

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内の要素を表すSiteMapNodeCollection

例外

SiteMapNodeCollectionは読み取り専用です。

index が 0 未満です。

-又は-

index Countよりも優れている。

セッターに指定された値は null

次のコード例では、Item[] インデクサーを使用して、SiteMapNode コレクションからSiteMapNodeCollection オブジェクトを取得する方法を示します。 この例では、 SiteMapNode オブジェクトは、 Remove メソッドを使用して内部配列の 2 番目の要素の位置から削除され、 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 オブジェクトを置き換えたりすることができます。

適用対象

こちらもご覧ください