错误提示如下
un.cs(12,3): error CS1502: 与“System.Console.WriteLine(string,
        object)”最匹配的重载方法具有一些无效参数
un.cs(12,49): error CS1503: 参数“2” : 无法从“int*”转换为“object”
un.cs(13,3): error CS1502: 与“System.Console.WriteLine(string,
        object)”最匹配的重载方法具有一些无效参数
un.cs(13,49): error CS1503: 参数“2” : 无法从“int*”转换为“object”

解决方案 »

  1.   

    试试这样:
    x.ToString();
    pX.ToString();
    pY.ToString();
      

  2.   

    using System;
    unsafe class myclass
    {
    public static int Main()
    {
    int x=10;
    int *pX,pY;
    string mn;
    pX=&x;
    pY=pX;
    *pY=20;
    mn=pX.ToString();
    Console.WriteLine("The result of 'x' is {0}",x);
    Console.WriteLine("The result of 'pX' is {0}",mn);
    //Console.WriteLine("The result of 'pX' is {0}",pX);
    //Console.WriteLine("The result of 'pY' is {0}",pY);
    return 0;
    }
    }
    这样不行,错误提示:
    Microsoft (R) Visual C# .NET Compiler version 7.00.9466
    for Microsoft (R) .NET Framework version 1.0.3705
    版权所有 (C) Microsoft Corporation 2001。保留所有权利。un.cs(12,6): error CS0023: 运算符“.”无法应用于“int*”类型的操作数
      

  3.   

    这样可以
    mn=System.Convert.ToString((long)pX);
      

  4.   

    为什么直接引用pX.ToString()的方法不行
      

  5.   

    pX为指针,非继承自Object,自然没有ToString()方法;要想察看指针中的内容,用*运算符应该可以吧(like C++):(*pX).ToString(); //(*pX) 为 int,有ToString()方法
      

  6.   

    假如要看指针的地址,即将指针转化为int或long,由于C#不允许指针向int、long的隐式转换(为了安全),只能显式转换才行:
    int temp = (int)pX;