C# Convert ToBoolean(SByte)

Description

Convert ToBoolean(SByte) converts the value of the specified 8-bit signed integer to an equivalent Boolean value.

Syntax

Convert.ToBoolean(SByte) has the following syntax.


[CLSCompliantAttribute(false)]
public static bool ToBoolean(
  sbyte value
)

Parameters

Convert.ToBoolean(SByte) has the following parameters.

  • value - The 8-bit signed integer to convert.

Returns

Convert.ToBoolean(SByte) method returns true if value is not zero; otherwise, false.

Example

The following example converts an array of SByte values to Boolean values.


//from  ww  w .  j  a va 2  s  .  c om
using System;
public class MainClass{
  public static void Main(String[] argv){  
    sbyte[] numbers = { SByte.MinValue, -1, 0, 10, 100, SByte.MaxValue };
    bool result;
    
    foreach (sbyte number in numbers)
    {
       result = Convert.ToBoolean(number);                                 
       Console.WriteLine("{0,-5}  -->  {1}", number, result);
    }

  }
}
    

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