关于c#中的ref和out

来源:互联网 发布:怎么做网站优化 编辑:程序博客网 时间:2024/05/29 10:20

看例子

 static void Main(string[] args)
        {
            int yp=5;
            fun_name(out yp,ref yp);
            Console.WriteLine(yp);


            Console.ReadKey();
        }
        static void fun_name( out int x,ref int y)
        {
            x = y;
            x += 5;
        }

首先:ref是必须先复制,out是必须出来时候有值(系统会检查,可以不初始化out的x的值;)

0 0
原创粉丝点击