C# Convert ToByte(Boolean)

Description

Convert ToByte(Boolean) converts the specified Boolean value to the equivalent 8-bit unsigned integer.

Syntax

Convert.ToByte(Boolean) has the following syntax.


public static byte ToByte(
  bool value
)

Parameters

Convert.ToByte(Boolean) has the following parameters.

  • value - The Boolean value to convert.

Returns

Convert.ToByte(Boolean) method returns The number 1 if value is true; otherwise, 0.

Example

The following example illustrates the conversion of Boolean to Byte values.


//from  w  w w  .ja  v  a  2 s.c  o m
using System;
public class MainClass{
  public static void Main(String[] argv){  
    bool falseFlag = false;
    bool trueFlag = true;
    
    Console.WriteLine("{0} converts to {1}.", falseFlag, 
                      Convert.ToByte(falseFlag));
    Console.WriteLine("{0} converts to {1}.", trueFlag, 
                      Convert.ToByte(trueFlag));

  }
}
    

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version