海兰!Iam现在学习refference类型,我不明白为什么x和y具有相同的内存地址?他们不应该有不同的地址吗?
class Program
{
static void Main(string[] args)
{
int x = 10; // int -> stack
int y = x; // assigning the value of num to mun.
DisplayMemAddress(x);
DisplayMemAddress(y);
Console.ReadLine();
}
static unsafe void DisplayMemAddress(int x)
{
int* ptr = &x;
Console.WriteLine("0x" + new IntPtr(ptr).ToString("x"));
}
}
Run Code Online (Sandbox Code Playgroud)