Boxing is to turn value type into reference type, right?
But when we copy a reference type into another reference type , it just copies the address, not the value. But when I convert int
to object
for example and copy to another object, it is not working the same way.
Example:
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
int x = 10;
object obj = x; //int vira reference type
object obj2 = obj; //copia o endereço do obj pro obj2, certo?
obj = 20; //modifica obj
System.Console.WriteLine((int)obj2); //mostra obj2, era pra mostrar 20, nao?
//por que mostra 10?
System.Console.ReadKey();
}
}
}