Int64.GetTypeCode 方法在 C# 中使用,พร้อม示例


C# 中的 Int64.GetTypeCode() 方法用于为值类型 Int64 返回 TypeCode。

语法

以下是语法 −

public TypeCode GetTypeCode ();

示例

让我们看一个示例来实现 Int64.GetTypeCode() 方法 −

using System;
public class Demo {
   public static void Main(){
      long val1 = 0;
      long val2 = Int64.MaxValue;
      Console.WriteLine("Value1 = "+val1);
      Console.WriteLine("Value2 = "+val2);
      Console.WriteLine("Are they equal? = "+val1.Equals(val2));
      Console.WriteLine("Value1 (HashCode) = "+val1.GetHashCode());
      Console.WriteLine("Value2 (HashCode) = "+val2.GetHashCode());
      TypeCode type1 = val1.GetTypeCode();
      TypeCode type2 = val2.GetTypeCode();
      Console.WriteLine("TypeCode for val1 = "+val1.GetTypeCode());
      Console.WriteLine("TypeCode for val2 = = "+val1.GetTypeCode());
   }
}

输出

将生成以下输出 −

Value1 = 0
Value2 = 9223372036854775807
Are they equal? = False
Value1 (HashCode) = 0
Value2 (HashCode) = -2147483648
TypeCode for val1 = Int64
TypeCode for val2 = = Int64

示例

让我们看另一个示例来实现 Int64.GetTypeCode() 方法 −

using System;
public class Demo {
   public static void Main(){
      long val1 = 8768768766;
      long val2 = Int64.MaxValue;
      Console.WriteLine("Value1 = "+val1);
      Console.WriteLine("Value2 = "+val2);
      Console.WriteLine("Are they equal? = "+val1.Equals(val2));
      Console.WriteLine("Value1 (HashCode) = "+val1.GetHashCode());
      Console.WriteLine("Value2 (HashCode) = "+val2.GetHashCode());
      TypeCode type1 = val1.GetTypeCode();
      TypeCode type2 = val2.GetTypeCode();
      Console.WriteLine("TypeCode for val1 = "+val1.GetTypeCode());
      Console.WriteLine("TypeCode for val2 = = "+val1.GetTypeCode());
   }
}

输出

将生成以下输出 −

Value1 = 8768768766
Value2 = 9223372036854775807
Are they equal? = False
Value1 (HashCode) = 178834172
Value2 (HashCode) = -2147483648
TypeCode for val1 = Int64
TypeCode for val2 = = Int64

更新日期:2019 年 11 月 13 日

82 次浏览

开启你的 职业生涯

完成课程获得认证

开始
广告