SiteMapNodeCollection.IndexOf(SiteMapNode) Méthode

Définition

Recherche l'objet SiteMapNode spécifié, puis retourne l'index de base zéro de la première occurrence dans l'ensemble de la collection.Searches for the specified SiteMapNode object, and then returns the zero-based index of the first occurrence within the entire collection.

public:
 virtual int IndexOf(System::Web::SiteMapNode ^ value);
public virtual int IndexOf (System.Web.SiteMapNode value);
abstract member IndexOf : System.Web.SiteMapNode -> int
override this.IndexOf : System.Web.SiteMapNode -> int
Public Overridable Function IndexOf (value As SiteMapNode) As Integer

Paramètres

value
SiteMapNode

SiteMapNode à rechercher dans SiteMapNodeCollection.The SiteMapNode to locate in the SiteMapNodeCollection.

Retours

Index de base zéro de la première occurrence de value dans l'ensemble du SiteMapNodeCollection, s'il existe ; sinon, -1.The zero-based index of the first occurrence of value within the entire SiteMapNodeCollection, if found; otherwise, -1.

Exemples

L’exemple de code suivant montre comment utiliser les Contains méthodes IndexOf et de la SiteMapNodeCollection classe.The following code example demonstrates how to use the Contains and IndexOf methods of the SiteMapNodeCollection class. Le code vérifie deux fournisseurs, AspNetXmlSiteMapProvider et MyXmlSiteMapProvider, pour les nœuds enfants du nœud racine qui sont des doublons.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.");
}
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    

Remarques

La IndexOf méthode détermine l’égalité en appelant Object.Equals la méthode.The IndexOf method determines equality by calling the Object.Equals method.

S’applique à