Search code examples
c#pass-by-referenceboxingunboxing

Pass by reference/value — Boxing/unboxing relation


I was reading about passing by reference in C# and while doing that I read the following sentence which confuses me.

"There is no boxing of a value type when it is passed by reference."

Though I know what boxing is, I think I miss the actual depth of information containted in this sentence. I know that it basically says no boxing occurs and of course neither does unboxing but what other conclusions could I draw from this? Is passing by value/reference anyhow related to boxing/unboxing?


Solution

  • If you are passing value types by reference there is no boxing and unboxing involved. There is memory aliasing, as is told in c# in nutshell book. You can even try it in Linqpad. After displaying it in IL code you will see there is no boxing/unboxing involved.