Boolean.GetTypeCode() Method in C# with Examples


The Boolean.GetTypeCode() method in C# is used to return the type code for the Boolean value type.

Syntax

The syntax is as follows −

public TypeCode GetTypeCode ();

Example

Let us now see an example −

 Live Demo

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());
   }
}

Output

This will produce the following output −

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

Example

Let us now see another example −

 Live Demo

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());
   }
}

Output

This will produce the following output −

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

Updated on: 03-Dec-2019

36 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements