Chris V. Chris V. - 3 months ago 17
C# Question

Using boolean values in resource file

In the application I'm working on there is a preference which can be enabled or disabled to convert all values to metric from imperial. I need to be able to save the preference even after the application is closed and reopened. The way I was thinking of going about it was to use a boolean value in a resource (.resx) file, which I could just set the value of whenever the box was checked or unchecked. Then, when the program is launched, it can simply check what the value of the resource bool is (true/false) and set the checkbox accordingly.

My problem is that when I try to use a resource of type bool or Boolean, when I check the box the application crashes and I get an error regarding memory, I believe it was a stack overflow exception.

My question is, is it just not possible to use and/or modify boolean values in a resource [.resx] file, or am I going about it incorrectly? If it's not possible, what alternative ways might there be to do what I'm trying to do?

Answer

If that is your problem don't go for bool values.

Go for int or string equivalent of bool like if you choose int then 0 or 1 or

bool res = Convert.ToBoolean(1);

or

bool res = Convert.ToBoolean(0);

If you go for string then "true" or "false".

bool res = Convert.ToBoolean("true");

or

bool res = Convert.ToBoolean("false");
Comments