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 具有固定的大小。

示例

下面的代码示例演示如何使用 Remove 方法从SiteMapNodeCollection集合中删除 SiteMapNode 对象,然后使用 方法将 SiteMapNode 对象追加到 的SiteMapNodeCollectionAdd末尾。 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 方法确定相等性。

适用于

另请参阅