using System;
class xianguo
{
    unsafe static void Main()
    {
        int* p;
        int var;       *p=10;
        
        Console.WriteLine(*p);
    }
}
为什么出现这种错误:使用了未赋值的局部变量“p”

解决方案 »

  1.   

    D:\button\ConsoleApplication1\Class1.cs(19): 不安全代码只会在使用 /unsafe 编译的情况下出现
    我比你还惨!  你的程序都出现了这个错误!
      

  2.   

    楼主,定义指针变量时要int* p = new int;
    然后*p=21;
      

  3.   

    zhangzengping(张增平) ( ) 信誉:100    Blog  2006-10-17 22:44:00  得分: 0  
     
     
       D:\button\ConsoleApplication1\Class1.cs(19): 不安全代码只会在使用 /unsafe 编译的情况下出现
    我比你还惨!  你的程序都出现了这个错误!
    -------------------------
    要对编译器进行设计
      单击项目菜单->属性,然后选择配置属性节点,在代码生成中选择允许不安全代码块,设置为true
     
      

  4.   

    还是不行啊
    using System;
    class xianguo
    {
        unsafe static void Main()
        {
            int *p = new int();
                  *p=10;
            
            Console.WriteLine(*p);
        }
    }
    错误 1 无法将类型“int”隐式转换为“int*”。存在一个显式转换(是否缺少强制转换?)