📜  C#中的Int64.GetTypeCode方法与示例

📅  最后修改于: 2021-05-29 14:52:42             🧑  作者: Mango

Int64.GetTypeCode方法用于获取值类型Int64的TypeCode。

下面的程序说明了上面讨论的方法的使用:

范例1:

// C# program to illustrate the
// Int64.GetTypeCode() Method
using System;
  
class GFG {
  
    // Main Method
    public static void Main()
    {
  
        // Taking long value
        // i.e. Int64
        long val = 4578123;
  
        // Getting the typecode for Int64
        // using GetTypeCode() method
        TypeCode result = val.GetTypeCode();
  
        // Display the TypeCode 
        Console.WriteLine("TypeCode for Int64 is: {0}",
                                               result);
    }
}
输出:
TypeCode for Int64 is: Int64

范例2:

// C# program to illustrate the
// Int64.GetTypeCode() Method
using System;
  
class GFG {
  
    // Main Method
    public static void Main()
    {
        // using result() Method
        result(Int64.MinValue);
        result(Int64.MaxValue);
    }
  
    // result() method
    public static void result(long val)
    {
  
        // using GetTypeCode() method
        TypeCode code = val.GetTypeCode();
  
        // Display the TypeCode
        Console.WriteLine("TypeCode for {0} is {1}",
                                         val, code);
    }
}
输出:
TypeCode for -9223372036854775808 is Int64
TypeCode for 9223372036854775807 is Int64

参考:

  • https://docs.microsoft.com/zh-cn/dotnet/api/system.int64.gettypecode?view=netframework-4.7.2