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

📅  最后修改于: 2021-05-29 23:36:56             🧑  作者: Mango

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

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

范例1:

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

范例2:

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

参考:

  • https://docs.microsoft.com/zh-cn/dotnet/api/system.sbyte.gettypecode?view=netcore-2.1