C# 中 Boolean.GetTypeCode() 方法附带示例


C# 中的 Boolean.GetTypeCode() 方法用于返回布尔值类型的类型代码。

语法

语法如下所示 −

public TypeCode GetTypeCode ();

示例

现在让我们来看一个示例 −

 在线演示

using System;
public class Demo {
   public static void Main(String[] args){
      string str = "JackSparrow!";
      bool val = true;
      char[] arr = { 'J', 'a'};
      Console.WriteLine("String = "+str);
      Console.WriteLine("String (after trim) = " + str.Trim(arr));
      Console.WriteLine("String (Hashcode) = "+str.GetHashCode());
      Console.WriteLine("Bool (Hashcode) = "+val.GetHashCode());
      Console.WriteLine("Bool (TypeCode) = "+val.GetTypeCode());
   }
}

输出

将产生以下输出 −

String = JackSparrow!
String (after trim) = ckSparrow!
String (Hashcode) = -203134198
Bool (Hashcode) = 1
Bool (TypeCode) = Boolean

示例

现在让我们来看另一个示例 −

 在线演示

using System;
public class Demo {
   public static void Main(String[] args){
      bool val1 = true;
      bool val2 = false;
      Console.WriteLine("Value1 (Hashcode) = "+val1.GetHashCode());
      Console.WriteLine("Value1 (TypeCode) = "+val1.GetTypeCode());
      Console.WriteLine("Value2 (Hashcode) = "+val2.GetHashCode());
      Console.WriteLine("Value2 (TypeCode) = "+val2.GetTypeCode());
   }
}

输出

将产生以下输出 −

Value1 (Hashcode) = 1
Value1 (TypeCode) = Boolean
Value2 (Hashcode) = 0
Value2 (TypeCode) = Boolean

更新于: 03-Dec-2019

46 次浏览

开启您的 职业生涯

通过完成课程获得认证

开始
广告