Guid.CompareTo Method (Object)
Compares this instance to a specified object and returns an indication of their relative values.
Assembly: mscorlib (in mscorlib.dll)
- Type: System.Object
An object to compare, or a null reference (Nothing in Visual Basic).
Return ValueType: System.Int32
A signed number indicating the relative values of this instance and value.
A negative integer
This instance is less than value.
This instance is equal to value.
A positive integer
This instance is greater than value, or value is a null reference (Nothing in Visual Basic).
The value parameter must be a null reference (Nothing in Visual Basic) or an instance of Guid; otherwise, an exception is thrown. Any instance of Guid, regardless of its value, is considered greater than a null reference (Nothing in Visual Basic).
It compares the Int32 values, and returns a result if they are unequal. If they are equal, it performs the next comparison.
It compares the first Int16 values, and returns a result if they are unequal. If they are equal, it performs the next comparison.
It compares the second Int16 values, and returns a result if they are unequal. If they are equal, it performs the next comparison.
If performs a byte-by-byte comparison of the next eight Byte values. When it encounters the first unequal pair, it returns the result. Otherwise, it returns 0 to indicate that the two Guid values are equal.
If two GUIDs have equal values for a component, the method compares the next component. When it finds a component whose values are unequal, it returns the result.
Note that the final eight bytes appear in the string representation of a Guid in reverse order, from low byte to high byte. For example, in the string representation of the Guid value "01e75c83-c6f5-4192-b57e-7427cec5560d", the final eight bytes are "b57e-7427cec5560d."
The following example uses the GuidAttribute attribute to assign a GUID to a class. It retrieves the value of this GUID by calling the Attribute.GetCustomAttribute method and passing the Value property of the returned GuidAttribute object to the Parse method. Then it compares that GUID with an array of values.
Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.