如何将字符串连接到int*?

Edw*_*rak 2 c# pointers unsafe

我正在练习使用C#中的指针(通过不安全的代码).所以现在,我只想将""连接到一个int*,所以我可以将它用作参数Console.WriteLine().

    static void Main(string[] args)
    {
        fullOfPointers();
    }
    static unsafe void fullOfPointers()
    {
        int value = 10;
        int* adress = &value;
        Console.WriteLine(&value+"");//error
        Console.ReadLine();
    }
Run Code Online (Sandbox Code Playgroud)

但编译器说运算符'+'不能用于int*和string.所以我该怎么做?

Sim*_*ead 6

如果你想要指针的内存地址..把它投射到int:

Console.WriteLine((int)&value); // will produce random memory address
Run Code Online (Sandbox Code Playgroud)

如果你想要的值address取消引用指针:

Console.WriteLine(*address); // produces 10
Run Code Online (Sandbox Code Playgroud)

我完全不知道你为什么试图连接任何东西string......这是没有必要的.