现在的位置: 首页 > 综合 > 正文

C#学习笔记四ref out参数

2012年09月02日 ⁄ 综合 ⁄ 共 482字 ⁄ 字号 评论关闭

namespace refout参数

{

    class Program

    {

        static void Main(string[] args)

        {

            int age = 20;

            int age1 = 20;

            IncAge(ref age);//函数调用也要加ref

            IncAge1(out age1);//这里用out时,参数不需要初始化,函数里会把参数当做没初始化来用。把参数扔进去就行了,返回处理后的值。

            Console.WriteLine(age);

            Console.ReadKey();

        }

 

        static void IncAge(ref int age) //传址(引用)要加ref

        {

            age++;

        }

 

        static void IncAge1(out int age)

        {

            age = 30;   //在这里给参数赋值。

        }

    }

}

抱歉!评论已关闭.