Прочитај на енглеском Уреди

Делите путем


XNode.EqualityComparer Property

Definition

Gets a comparer that can compare two nodes for value equality.

C#
public static System.Xml.Linq.XNodeEqualityComparer EqualityComparer { get; }

Property Value

A XNodeEqualityComparer that can compare two nodes for value equality.

Examples

The following example uses this property to retrieve an XNodeEqualityComparer, which implements the System.Collections.IEqualityComparer and System.Collections.Generic.IEqualityComparer<T> interfaces. It creates a dictionary that uses this property.

C#
XElement xmlTree = new XElement("Root",  
    new XElement("Child1", 1),  
    new XElement("Child2", 2),  
    new XElement("Child3", 3),  
    new XElement("Child4", 4),  
    new XElement("Child5", 5)  
);  

Dictionary<XNode, string> nodeDictionary = new Dictionary<XNode, string>(XNode.EqualityComparer);  
nodeDictionary.Add(xmlTree.Element("Child5"), "Child 5 Information");  
nodeDictionary.Add(xmlTree.Element("Child3"), "Child 3 Information");  
nodeDictionary.Add(xmlTree.Element("Child1"), "Child 1 Information");  

string str = nodeDictionary[xmlTree.Element("Child3")];  
Console.WriteLine(str);  

This example produces the following output:

Child 3 Information  

Applies to

Производ Верзије
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 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
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

See also