On Sat, 24 Mar 2007 03:00:57 -0700, Jamey Bon <jb***@ue.comwrote:
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;
I see. Well, it appears to me you've already gotten a couple of examples
of code that may work fine for you. Göran's looks closer to what you're
asking for, but both are more on the right track than the enum, given your
clarification.
However, I'd have to agree that it would probably make more sense to just
use variable names that correspond better to just using a bool, if you're
just going to treat the variable as a bool anyway. In fact, in your
example, I fail to see how "Yes" is in any way better than "true". A
variable with an "is" at the front is classic boolean everywhere else in
..NET, and I see no benefit to using "yes" or "no" as an assignment rather
than the original boolean values.
For what it's worth:
What you describe should allow me to (if I have the C# syntax correct) do
something like this:
bool isComplete;
isComplete = YesNo.Yes;
Actually, the enum doesn't let you do this. You need to cast the enum
explicitly for it to work. Between the explicit cast and having to
reference the enum type, just using the original "bool" values sure looks
more and more desirable to me. :) You could bypass the enum by declaring
a couple of constants within your class that match the enum values, but
that's even more kludgy and you still need to explicitly cast even then.
Pete