如何打印bool变量的地址?

时间:2015-01-23 13:08:39

标签: c#

bool b;
unsafe
{    
    bool* p1 = &b; 
    Console.WriteLine("p1: {0}", p1->ToString());
}

给我

  

P1:假

但我想打印地址。我该怎么办?

1 个答案:

答案 0 :(得分:3)

using System;

namespace Test81
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            bool b;
            unsafe
            {    
                bool* p1 = &b; 
                Console.WriteLine("p1: 0x{0:X}", new IntPtr(p1).ToInt64());
            }
        }
    }
}