当前位置: 首页>>代码示例>>C#>>正文


C# Guid.CompareTo方法代码示例

本文整理汇总了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 }
}
开发者ID:.NET开发者,项目名称:System,代码行数:24,代码来源:Guid.CompareTo

输出:

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);
         }                     
      }                         
   }
}
开发者ID:.NET开发者,项目名称:System,代码行数:28,代码来源:Guid.CompareTo

输出:

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


注:本文中的System.Guid.CompareTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。