通过


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到使用Add该方法的SiteMapNodeCollection末尾。 如果为 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 该方法来确定相等性。

适用于

另请参阅