convert int to bool c# code example
Example 1: how to convert string to bool c#
string sample = "True";
bool myBool = bool.Parse(sample);
///or
bool myBool = Convert.ToBoolean(sample);
Example 2: int to bool c#
int i = 0;
bool b = Convert.ToBoolean(i);
Example 3: c# int to bool
// Simple way, may crash if intValue > 1
int intValue = 1;
bool boolValue = intValue != 0;
// value of boolValue: true
// Better way
int intValue = 1;
bool boolValue = System.Convert.ToBoolean(intValue);
// value of boolValue: true