C++代码
                    float* prob ;
                    gmax = 255;
                    while (prob[gmax] == 0 && gmax > 0)
                        gmax--;粘在C#中
第三行
产生错误:使用了未赋值的局部变量"prob".如何解决?
本人菜鸟,望高人指点,小女子在此谢过。

解决方案 »

  1.   


    float* prob = new float[255] ;
      

  2.   


            unsafe static void Main(string[] args)
            {
                //写法一,分配在堆上
                  int gmax = 255;
                fixed (float* prob = new float[gmax])
                    while (prob[gmax] == 0 && gmax > 0)
                        gmax--;            //写法二,分配在堆栈
                  int gmax = 255;
                float* prob = stackalloc float[gmax];
                while (prob[gmax] == 0 && gmax > 0)
                    gmax--;
            }
      

  3.   

    会产生错误  无法将类型“float[]”隐式转换为“float*”
      

  4.   

    c#中没有指针的
    直接
    float[] prob=new float[55];
    就可以的
      

  5.   

    你是在C#中的啊,我以为你在VS中用的C++呢
    C#的话float[] prob = new float[255]{1.2,1.3,...............................};
      gmax = 255;
      while (prob[gmax] == 0 && gmax > 0)
      gmax--;
      

  6.   

    楼上有人告诉你了  加UNSAFE说明是非托管代码!
      

  7.   


    别忘了DELETE。UNSAFE里边的东西GC不管擦屁股的。