XNodeEqualityComparer.GetHashCode(XNode) Metodo

Definizione

Restituisce un codice hash basato su un oggetto XNode.

public:
 virtual int GetHashCode(System::Xml::Linq::XNode ^ obj);
public int GetHashCode(System.Xml.Linq.XNode obj);
override this.GetHashCode : System.Xml.Linq.XNode -> int
Public Function GetHashCode (obj As XNode) As Integer

Parametri

obj
XNode

Oggetto XNode da hashre.

Valori restituiti

Oggetto Int32 contenente un codice hash basato su valori per il nodo.

Implementazioni

Esempio

Nell'esempio seguente viene utilizzato questo metodo per ottenere un codice hash completo per un albero XML.

XElement xmlTree = new XElement("Root",
    new XAttribute("Att1", 1),
    new XAttribute("Att2", 2),
    new XElement("Child1", 1),
    new XElement("Child2", "some content")
);
XNodeEqualityComparer equalityComparer = new XNodeEqualityComparer();
Console.WriteLine("HashCode: {0}", equalityComparer.GetHashCode(xmlTree).ToString("X"));
xmlTree.Add(new XElement("NewChild", "new content"));
Console.WriteLine("HashCode: {0}", equalityComparer.GetHashCode(xmlTree).ToString("X"));

In questo esempio viene generato l'output seguente:

HashCode: 958CCD0
HashCode: AD26516B

Commenti

L'implementazione XNode di GetHashCode è basata sull'identità referenziale del nodo. Questo metodo calcola un codice hash profondo in base al valore del nodo e a tutti i discendenti. Il codice hash riflette tutti gli attributi e tutti i nodi discendenti.

Si applica a

Vedi anche