日期:2014-05-19  浏览次数:20834 次

下面的代码我该怎么改啊,要用指针改值,谢谢我是新手
using   System;
using   System.Collections.Generic;
using   System.Text;

namespace   Hello_Word
{
        class   Program
        {
                static   void   Main(string[]   args)
                {
                        int   num2   =   14000;
                        int   *   p;
                        p   =   &num2;
                        Test(*p);
                        Console.WriteLine( "num2= "+num2);
                }

                  static   void   Test(int   *pp)
                {
                        *pp   =   400;
                }
        }        
}


------解决方案--------------------
using System;
using System.Collections.Generic;
using System.Text;

namespace Hello_Word
{
class Program
{
static unsafe void Main(string[] args)
{
int num2 = 14000;
int * p;
p = &num2;
Test(*p);
Console.WriteLine( "num2= "+num2);
}

static unsafe void Test(int *pp)
{
*pp = 400;
}
}
}


然后在工程那地方右键属性,找到允许不安全代码那地方打勾,然后就可以了
友情提示,.net里不要这么使用指针,而应该用ref.
信誉,给分。