Mono Class Library: System.Convert Overview | Members

System.Convert.ToBoolean Method

Converts a int to a bool . [Edit]

public static bool ToBoolean (int value)

Parameters

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

Returns

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

Remarks

Documentation for this section has not yet been entered. [Edit]

Example

The following example demonstrates converting int values to bool values.

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

The output is

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

Requirements

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