本文整理汇总了C#中System.Guid.CompareTo方法的典型用法代码示例。如果您正苦于以下问题:C# Guid.CompareTo方法的具体用法?C# Guid.CompareTo怎么用?C# Guid.CompareTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Guid
的用法示例。
在下文中一共展示了Guid.CompareTo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
public class Example
{
public static void Main()
{
Guid mainGuid = Guid.Parse("01e75c83-c6f5-4192-b57e-7427cec5560d");
unchecked {
Guid guid2 = new Guid(0x01e75c83, (short) 0xc6f5,
0x4192,
new Byte[] { 0xb5, 0x7e, 0x74, 0x27, 0xce, 0xc5, 0x56, 0x0c} );
Guid guid3 = Guid.Parse("01e75c84-c6f5-4192-b57e-7427cec5560d");
Console.WriteLine("{0} {1:F} {2}", mainGuid,
(Comparison) mainGuid.CompareTo(guid2), guid2);
Console.WriteLine("{0} {1:F} {2}", mainGuid,
(Comparison) mainGuid.CompareTo(guid3), guid3);
}
}
private enum Comparison
{ LessThan = -1, Equals = 0, GreaterThan = 1 }
}
输出:
01e75c83-c6f5-4192-b57e-7427cec5560d GreaterThan 01e75c83-c6f5-4192-b57e-7427cec5560c 01e75c83-c6f5-4192-b57e-7427cec5560d LessThan 01e75c84-c6f5-4192-b57e-7427cec5560d
示例2: Main
//引入命名空间
using System;
using System.Runtime.InteropServices;
[Guid("936DA01F-9ABD-4d9d-80C7-02AF85C822A8")]
public class Example
{
public static void Main()
{
GuidAttribute guidAttr = (GuidAttribute) Attribute.GetCustomAttribute(typeof(Example),
typeof(GuidAttribute));
Guid guidValue = Guid.Parse(guidAttr.Value);
Object[] values = { null , 16,
Guid.Parse("01e75c83-c6f5-4192-b57e-7427cec5560d"),
guidValue };
foreach (var value in values) {
try {
Console.WriteLine("{0} and {1}: {2}", guidValue,
value == null ? "null" : value,
guidValue.CompareTo(value));
}
catch (ArgumentException) {
Console.WriteLine("Cannot compare {0} and {1}", guidValue,
value == null ? "null" : value);
}
}
}
}
输出:
936da01f-9abd-4d9d-80c7-02af85c822a8 and null: 1 Cannot compare 936da01f-9abd-4d9d-80c7-02af85c822a8 and 16 936da01f-9abd-4d9d-80c7-02af85c822a8 and 01e75c83-c6f5-4192-b57e-7427cec5560d: 1 936da01f-9abd-4d9d-80c7-02af85c822a8 and 936da01f-9abd-4d9d-80c7-02af85c822a8: 0