int to bool csharp
Code Example - int to bool csharp
int i = 0;
bool b = Convert.ToBoolean(i);
csharp 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
csharp bool to int
bool t = true;
bool f = false;
var a = Unsafe.As<bool, int>(ref t);
var b = Unsafe.As<bool, int>(ref f);
Console.WriteLine(a); // 1
Console.WriteLine(b); // 0