The difference between converting and unboxing: read my mind, compiler!

http://philosopherdeveloper.com/posts/difference-between-converting-and-unboxing.html

Advertisements

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

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: