小编gal*_*ris的帖子

奇怪的引用行为(int的相同内存地址)

海兰!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)

c# int pointers reference

2
推荐指数
1
解决办法
214
查看次数

标签 统计

c# ×1

int ×1

pointers ×1

reference ×1