Convert bool to char in C#

Hi I want to convert a bool to a char. The standard method in C# seems [1] to be

bool vIn = true;
char vOut = Convert.ToChar(vIn);

But for me Unity3D produces the following error:

System.Convert.ToChar (Boolean value)
InvalidCastException: This conversion is not supported.

I am using the System namespace of course. Thanks for any help. I am a C#/Unity3D rookie.

[1] Convert bool to char in C# | Convert Data Types

try this

char vOut = (vIn == true ? '1' : '0');

Did not know that bool.toString() didn’t exist but whatever. I guess you could just create a simple static method to parse boolean to string :

static string BoolToString(bool b)
return b ? "true":"false";

Just put it in an Util class and you would just have to do Util.BoolToString(b)

Hope it helped :wink:


try this:

bool vIn = false;
char vOut = (char)Convert.ToByte(vIn);

this runs for me.