Recently, we’ve discussed the adverse effects that boxing and unboxing can have on the performance of your application. Furthermore, during episode two, we mentioned the unintentional use of boxing when using interfaces and how using generic interfaces instead can help. [Read more…]
Steps to Understanding Boxing and Unboxing
I could start by telling you that wrapping a value type in an Object is boxing. There, we’re done right? I mean, you now know what that means, yeah?! So, you could probably then deduce that unboxing would be taking that variable back out of the object?! SIMPLE! Cool…so then…why do we care? Good question. Let’s see if we can go ahead and answer that! [Read more…]
Boxing and Unboxing in .NET
Podcast: Play in new window | Download
Subscribe: Apple Podcasts | Spotify | TuneIn | RSS
This episode is all about boxing and unboxing. We discuss memory management, the pros (yes, there are a few!) and cons of boxing/unboxing, some of the weird side effects and how to you can avoid it with generics and ToString methods.
Download the episode on iTunes or Stitcher and make sure to drop your feedback on iTunes.
Thanks for listening! [Read more…]
Avoiding boxing in String and Console methods
Unlike Java, C# has a unified type system. Both reference types AND values inherit from system.object which means that you can have a method that takes in both value and reference types by their common parent, System.Object.
This is used to great effect in the String class, where you have methods like CompareTo(Object), String.Concat(Object,Object) and my personal favorite: Format(String, Object[]).
These methods are really convenient, but unfortunately boxing occurs when you pass in value types.
However, we’ve come across a nice trick for skipping those operations. [Read more…]
Boxing and Unboxing in C#: 7 Deadly Sins
You might have had the anti boxing and unboxing rhetoric pounded into your head.
In the .NET world they’re often mentioned as an unfortunate side-effect of backwards compatibility. A reminder of life before generics…
…before Linq. *shudder*
Let’s take a look at 7 of the reasons why programmers beat up on boxing. [Read more…]