Mono Class Library: System.Convert Overview | Members

System.Convert.ToBoolean Method

Converts a sbyte to a bool . [Edit]

[System.CLSCompliant(false)]
public static bool ToBoolean (sbyte value)

Parameters

value
The 8-bit signed integer value to be converted. [Edit]

Returns

true if value is non-zero; false if value is zero. [Edit]

Remarks

This member is not CLS-compliant. For a CLS-compliant alternative, use Convert.ToBoolean(object)(short). [Edit]

Example

The following example demonstrates converting sbyte values to bool values.

C# Example
using System;
class ConvertBoolTest {
    static public void Main() {
        sbyte sbyte0 = (sbyte) 0;
        sbyte sbyte1 = (sbyte) 1; 
        sbyte sbyte2 = (sbyte) -2;
        bool bool0 = Convert.ToBoolean(sbyte0);
        bool bool1 = Convert.ToBoolean(sbyte1);
        bool bool2 = Convert.ToBoolean(sbyte2);
        Console.WriteLine("(sbyte) {0} as bool = {1}",sbyte0,bool0);
        Console.WriteLine("(sbyte) {0} as bool = {1}",sbyte1,bool1);
        Console.WriteLine("(sbyte) {0} as bool = {1}",sbyte2,bool2);
    }
}

The output is

(sbyte) 0 as bool = False
(sbyte) 1 as bool = True
(sbyte) -2 as bool = True

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0