Does this cause boxing to occur?

  • Thread starter Thread starter Phill
  • Start date Start date
P

Phill

Does this cause boxing to occur?

class Test
{
void myFunc(ref int theInt)
{
theInt = 10;
}

Test()
{
int x = 0;
myFunc(ref x);
}
}

So is x being boxed into an Object instance and passed by reference
that way and then unboxed back into an int? Or is it like C++ where
the address of x on the stack is really being passed & worked on w/o
any object creation happening?
 
Hi,
Boxing doesn't happen here. Its just the address of the variable that is
passed to the function.

Does this cause boxing to occur?

class Test
{
void myFunc(ref int theInt)
{
theInt = 10;
}

Test()
{
int x = 0;
myFunc(ref x);
}
}

So is x being boxed into an Object instance and passed by reference
that way and then unboxed back into an int? Or is it like C++ where
the address of x on the stack is really being passed & worked on w/o
any object creation happening?
 
Back
Top