SiteMapNodeCollection.Contains(SiteMapNode) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
确定集合是否包含特定的 SiteMapNode 对象。
public:
virtual bool Contains(System::Web::SiteMapNode ^ value);
public virtual bool Contains (System.Web.SiteMapNode value);
abstract member Contains : System.Web.SiteMapNode -> bool
override this.Contains : System.Web.SiteMapNode -> bool
Public Overridable Function Contains (value As SiteMapNode) As Boolean
参数
- value
- SiteMapNode
要在 SiteMapNode 中定位的 SiteMapNodeCollection。
返回
如果 SiteMapNodeCollection 包含指定的 SiteMapNode,则为 true
;否则为 false
。
示例
下面的代码示例演示如何使用 Contains 类的和 IndexOf 方法 SiteMapNodeCollection 。 该代码检查两个提供程序, AspNetXmlSiteMapProvider
以及 MyXmlSiteMapProvider
是否检查重复的根节点的子节点。
String providername1 = "AspNetXmlSiteMapProvider";
String providername2 = "MyXmlSiteMapProvider";
SiteMapProviderCollection providers = SiteMap.Providers;
if (providers[providername1] != null && providers[providername2] != null)
{
SiteMapProvider provider1 = providers[providername1];
SiteMapProvider provider2 = providers[providername2];
SiteMapNodeCollection collection1 = provider1.RootNode.ChildNodes;
SiteMapNodeCollection collection2 = provider2.RootNode.ChildNodes;
int matches = 0;
foreach (SiteMapNode node in collection1)
{
if (collection2.Contains(node))
{
Response.Write("Match found at " +
providername1 + ", index = " +
collection1.IndexOf(node) + " with " +
providername2 + ", index = " +
collection2.IndexOf(node) + ".<br />");
matches++;
}
}
Response.Write("Number of matches found = " +
matches.ToString() + ".");
}
else
{
Response.Write(providername1 + " or " +
providername2 + " not found.");
}
Dim providername1 As String = "xAspNetXmlSiteMapProvider"
Dim providername2 As String = "MyXmlSiteMapProvider"
Dim providers As SiteMapProviderCollection = SiteMap.Providers
If Not (providers(providername1) Is Nothing) AndAlso Not (providers(providername2) Is Nothing) Then
Dim provider1 As SiteMapProvider = providers(providername1)
Dim provider2 As SiteMapProvider = providers(providername2)
Dim collection1 As SiteMapNodeCollection = provider1.RootNode.ChildNodes
Dim collection2 As SiteMapNodeCollection = provider2.RootNode.ChildNodes
Dim matches As Integer = 0
Dim node As SiteMapNode
For Each node In collection1
If collection2.Contains(node) Then
Response.Write("Match found at " & _
providername1 & ", index = " & _
collection1.IndexOf(node) & " with " & _
providername2 & ", index = " & _
collection2.IndexOf(node) & ".<br />")
matches += 1
End If
Next node
Response.Write("Number of matches found = " & _
matches.ToString() + ".")
Else
Response.Write(providername1 & " or " & _
providername2 & " not found.")
End If
注解
该方法 Contains 通过调用 Object.Equals 该方法来确定相等性。