c#如何可以像C++的指针一样 可以取得一个变量的地址值,如:
    int *d;
    cout<<d是得到d的地址值。
    在C#中如何实现

解决方案 »

  1.   


                unsafe
                {
                    int x = 20;
                    int* pi = &x;
                    Console.WriteLine("0x{0:X}",(uint)pi);
                }
      

  2.   

    在项目->属性->生成 中勾选允许不安全代码.
      

  3.   

    LZ,参考C#中的两个修饰符:
    ref
    out
      

  4.   

    static void Main()
        {
            int number;
            unsafe 
            {
                int* p = &number;
                *p = 0xffff;
                System.Console.WriteLine("Value at the location pointed to by p: {0:X}", *p);
                System.Console.WriteLine("The address stored in p: {0}", p->ToString());
            }
            System.Console.WriteLine("Value of the variable number: {0:X}", number);
        }
      

  5.   

    http://blog.csdn.net/liang4571231/archive/2008/09/08/2898660.aspx
    这是我blog里关于这个问题的分析,有时间可以去看下