共用方式為


SiteMapNodeCollection.Remove(SiteMapNode) 方法

定義

從集合中移除指定的 SiteMapNode 物件。

public:
 virtual void Remove(System::Web::SiteMapNode ^ value);
public virtual void Remove (System.Web.SiteMapNode value);
abstract member Remove : System.Web.SiteMapNode -> unit
override this.Remove : System.Web.SiteMapNode -> unit
Public Overridable Sub Remove (value As SiteMapNode)

參數

value
SiteMapNode

要從 SiteMapNode 移除的 SiteMapNodeCollection

例外狀況

value 不存在於集合中。

valuenull

SiteMapNodeCollection 為唯讀。

-或-

SiteMapNodeCollection 具有固定的大小。

範例

下列程式碼範例示範如何使用 方法從 SiteMapNodeCollection 集合中移除 SiteMapNode 物件,然後使用 方法將 SiteMapNode 物件附加至 結尾 SiteMapNodeCollectionAddRemove SiteMapNodeCollection如果 是唯讀的, NotSupportedException 則會攔截例外狀況。


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

備註

您可以藉由檢查 IsReadOnly 屬性來測試集合是否 SiteMapNodeCollection 為唯讀。

方法會 Remove 呼叫 Object.Equals 方法來判斷相等。

適用於

另請參閱