XNodeDocumentOrderComparer.Compare(XNode, XNode) Method
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Compares two nodes to determine their relative document order.
public:
virtual int Compare(System::Xml::Linq::XNode ^ x, System::Xml::Linq::XNode ^ y);
public int Compare (System.Xml.Linq.XNode x, System.Xml.Linq.XNode y);
public int Compare (System.Xml.Linq.XNode? x, System.Xml.Linq.XNode? y);
abstract member Compare : System.Xml.Linq.XNode * System.Xml.Linq.XNode -> int
override this.Compare : System.Xml.Linq.XNode * System.Xml.Linq.XNode -> int
Public Function Compare (x As XNode, y As XNode) As Integer
An Int32 that contains 0 if the nodes are equal; -1 if x
is before y
; 1 if x
is after y
.
The two nodes do not share a common ancestor.
The following example uses this class to compare document order for two nodes.
XElement xmlTree = new XElement("Root",
new XText("Text content."),
new XElement("Child1", "child1 content"),
new XElement("Child2", "child2 content"),
new XElement("Child3", "child3 content"),
new XText("More text content."),
new XElement("Child4", "child4 content"),
new XElement("Child5", "child5 content")
);
XElement child3 = xmlTree.Element("Child3");
XElement child5 = xmlTree.Element("Child5");
XNodeDocumentOrderComparer documentOrderComparer = new XNodeDocumentOrderComparer();
int val = documentOrderComparer.Compare(child3, child5);
if (val == 0)
Console.WriteLine("Child3 is same as Child5");
else if (val < 0)
Console.WriteLine("Child3 is before Child5");
else
Console.WriteLine("Child3 is after Child5");
This example produces the following output:
Child3 is before Child5
We recommend that instead of using this class directly, you use the InDocumentOrder method. This class is used internally by that method.
Producto | Versiones |
---|---|
.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 |
.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 |
Comentarios de .NET
.NET es un proyecto de código abierto. Seleccione un vínculo para proporcionar comentarios: