首页 > 其他分享 >ref参数

ref参数

时间:2023-03-19 20:58:37浏览次数:31  
标签:salary Console 方法 参数 static ref

 ref参数:

能够将一个变量带入一个方法中进行改变,改变完成后,在将改变后的值带出方法。

ref参数要求在方法外必须为其赋值,而方法内可以不赋值。

using System;

namespace ref参数
{
    class Program
    {
        static void Main(string[] args)
        {
            double salary = 5000;
            JiangJin(ref salary);//调用的时候也需要写上ref
            Console.WriteLine(salary);
            Console.ReadKey();
        }
        //ref参数可以在方法中就改变变量的值,然后把计算完成后的值带出方法。
        public static void JiangJin(ref double s)
        {
            s += 500;
        }
    }
}

 

标签:salary,Console,方法,参数,static,ref
From: https://www.cnblogs.com/chungeblog/p/17234210.html

相关文章