首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

这个小程序编译不过去,该怎么解决

2013-03-27 
这个小程序编译不过去在学习C#,学到用ref引用参数,可这个程序就是编译不过去,请各位大侠帮助菜鸟看看,谢谢

这个小程序编译不过去
在学习C#,学到用ref引用参数,可这个程序就是编译不过去,请各位大侠帮助菜鸟看看,谢谢。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace helloworld
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = 0;
            Console.WriteLine(a.ToString());   //输出是0
            public void modifyvalue(ref int a)
            {
                a=1;
            }
            Console.WriteLine(a.ToString());   //输出是1
                Console.ReadKey();
        }
    }
}

[解决办法]

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace helloworld
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = 0;
            Console.WriteLine(a.ToString());   //输出是0
            modifyvalue(ref a);
            Console.WriteLine(a.ToString());   //输出是1
                Console.ReadKey();
        }
    }
    public static void modifyvalue(ref int a)
    {
         a=1;
    }
}

热点排行