本文整理匯總了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