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

例外

SiteMapNodeCollection は読み取り専用です。

index が 0 未満です。

  • または - indexCount より大きい値です。

設定側に指定された値が null です。

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

適用対象

こちらもご覧ください