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;   //在这里给参数赋值。

        }

    }

}

相关文章:

  • 2022-01-30
  • 2022-12-23
  • 2021-05-28
  • 2022-12-23
  • 2022-02-18
  • 2022-12-23
  • 2021-05-22
  • 2021-10-11
猜你喜欢
  • 2021-06-28
  • 2022-12-23
  • 2021-04-08
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案