SiteMapNodeCollection.IndexOf(SiteMapNode) Method

Definition

Searches for the specified SiteMapNode object, and then returns the zero-based index of the first occurrence within the entire collection.

C#
public virtual int IndexOf(System.Web.SiteMapNode value);

Parameters

value
SiteMapNode

The SiteMapNode to locate in the SiteMapNodeCollection.

Returns

The zero-based index of the first occurrence of value within the entire SiteMapNodeCollection, if found; otherwise, -1.

Examples

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.

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

Remarks

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

Applies to

Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1