[...] I would like to
do something like an Enumeration to use "constants" like Yes to
indica te
true and No for false. But since there seems to be no underlying 0
or
non-zero for boolean values in C#, I am not sure how to handle this.
A ny
advice would be appreciated.
Have you tried simply using "bool" as the underlying type for the
enum? You should be able to get "Yes" and "No" defined just fine
that way. For example:
enum YesNo : bool { No = false, Yes = true };
Or is there something more complicated you're trying to accomplish?
If so, you should clarify that.
Pete
Hmmm. I believe I failed to think this out properly before I asked the
question. What I really wanted was the ability to directly assign "Yes"
instead of "true" to a boolean variable, like this:
bool isComplete;
isComplete = Yes;
Something like this is possible in some other languages by several means
that all boil down to making false, by whatever name (here it would be
"No") = 0, and true (or, "Yes") = 1. But since C# doesn't treat boolean
values as 0 and 1, I am not sure this is possible.
What you describe should allow me to (if I have the C# syntax correct) do
something like this:
bool isComplete;
isComplete = YesNo.Yes;
This will actually work for my immediate needs and serves to make me
think more clearly about how boolean values are treated in C#. Thank you
for your help.
Now let me go digest what Mattias has been kind enough to post for me.