SiteMapNodeCollection.Contains Method (SiteMapNode)

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Determines whether the collection contains a specific SiteMapNode object.

Namespace:   System.Web
Assembly:  System.Web (in System.Web.dll)

public virtual bool Contains(
	SiteMapNode value
)

Parameters

value
Type: System.Web.SiteMapNode

The SiteMapNode to locate in the SiteMapNodeCollection.

Return Value

Type: System.Boolean

true if the SiteMapNodeCollection contains the specified SiteMapNode; otherwise, false.

The Contains method determines equality by calling the Object.Equals method.

The following code example demonstrates how to use the Contains and IndexOf methods of the SiteMapNodeCollection class. The code checks two providers, AspNetXmlSiteMapProvider and MyXmlSiteMapProvider, for child nodes of the root node that are duplicates.

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.");
}

.NET Framework
Available since 2.0
Return to top
Show: