• Anonymous (unregistered) in reply to Community of Realists Against Psuedo-nulls (CRAP)
    Can someone explain to me why for enums (not limited to booleans here) some programmers like putting a "default" or "unknown" value which is, by all accounts, a pseudo-null as it designed to not be a valid option and usually never fully implemented.
    Perhaps the guy is just coming from a C background, where enums are basically integers, and hence non nullable.
  • (cs) in reply to methinks
    methinks:
    Brian White:
    Larry:
    TRWTF is "Integers" that don't encompass the entire range of values.

    TRWTF is "Integers" period. Screw integers.

    So I suppose you are one of those people who invite absolute disaster into their projects by using some float type to represent e.g. money values or the like? ;oP

    I just went through a project where the contractors used double for local variables to hold currency values. We noticed when we received a report stating that an account balance was off by $7.105427357601E-15.

  • I forgot (unregistered) in reply to Tanuki
    Tanuki:
    A lot of talk about booleans. Can I do -this- in C#?
    int b_acc += (int) b;
    
    In where b is a bool.

    lol @ the WTF there (allocating an int then incrementing it assigning an initial value;

    Assuming that you did allocated b_acc and set it correctly elsewhere, I imagine something like the following would get the job done!

    b_acc += (b ? 1 : 0);

    This will convert the bool into an int in a clear and concise way. It would eve work under C++.

    CAPTHA - veniam --- can I get that on a sandwich

  • Tanuki (unregistered) in reply to I forgot

    Yeah, made a mistake right there.

    It just came to my mind that once I had a situation in Java, in where there was a set of boolean values and I needed to count the number of trues. Of course, in Java its a grave offence even to think of cast a boolean into anything, so I did that with ternary the conditional too.

    "What's the point?" You say. I just wanted to know if its possible in C# to use booleans in integer exressions.

  • charles (unregistered) in reply to bool b

    Since it's an extension method, no need to menmtion the type in the method name...

    public static string ToStr(this bool b){return b.ToString();}

  • foljs (unregistered) in reply to jumentum

    Pedantic much?

  • BAF (unregistered) in reply to frits
    frits:
    C# fun facts: Boolean keywords are all lowercase. ToString() and TrueString/FalseString are capitalized. Parse() expects capitalization.

    This method will not return "true" or "false" as is.

    MSDN clearly states Parse() is case insensitive. RTFM, noob.

Leave a comment on “Truthful Strings”

Log In or post as a guest

Replying to comment #:

« Return to Article