4 thoughts on “The difference between converting and unboxing: read my mind, compiler!

  1. Chris Boden says:

    Hahaha, that dramatization is wonderful. I appreciate your help with that problem immensely. Thank you!

  2. Raul Vejar says:

    Nice post, the dialogs are hilarious.
    BTW, is there any way to avoid having to unbox to the specific type besides using something parsing the object into the generic type?
    For example if I know the property is numeric I can unbox it as an object and then parse the string representation into a double or decimal thus avoiding the intermediate cast. I would really like something that would actually trigger the implicit conversion on runtime

    • Daniel says:

      The standard approach to accomplish what you’re asking for (if I understand you correctly) is to use the System.Convert class and one of its methods based on the type you want: Convert.ToDouble, Convert.ToDecimal, etc.

Leave a reply to Chris Boden Cancel reply