Boxing and Unboxing in .NET Framework with C#

Boxing converts value type to reference type and unboxing does it in reverse, reference to value types. One example is if we want to convert integer to Object which we’ll do with the help of Boxing.
int i = 1;
object o = (object) i;

object o = 1;
int i = (int) o;

There is an overhead associated with boxing and unboxing so it’s best to avoid them by doing following. Implement type specific version of the method by overriding them. Use generics instead of objects if possible. Override ToString, Equals, GetHash with defining structures.

  // String conversion (no boxing).
    public override string ToString()
    {
        return this.Value.ToString();
    }