Answers for "c# cast integer to bool"

C#
0

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
Posted by: Guest on March-18-2021

C# Answers by Framework

Browse Popular Code Answers by Language