Three valued logic with nullable bool?

.net, c#, enums, logic, nullable

Solution

I'd stick with ENUMS.

My three reasons that come to mind in a second:

- It's more readable.

- You avoid null poiters and unnecessary null-check code.

- You can add another option (eg. 'Ask me later') without refactoring your whole source.

Problem

I have a easy control with nothing chosen at begin and user decide to set yes or no. All in all a standard example for three valued logic. So my first thought was to take nullable bool to persist. Normally this would leads me to some annoying `if (var == null) { ... }` (or something similar). Second thought brings me to Enums. ``` public enum Selection { Yes, No, NotChoosenYet } ``` In my context this brings to some enum to bool converts, but this is not a show-stopper. All in all I tend to chose the "Enum-way", because is more readable. I searched SO for a while but can't find a question which brings me a sept forward. Is there a better way which I do not consider yet? Maybe a standard .Net-Type which can make thinks more easy?

Original source