c#

1.前言

传递参数,不需要返回值,对懒人很舒服哟,缺点是不好定位数据

2.操作

using System;

namespace ConsoleApp1.letVlaueGo
{
    public class DoValue
    {
        public static void Main(string[] args)
        {
            //初始值
             int a = 1;
             int b = 2;
            /*
             * main方法不允许使用this调用同级页面的方法,只有在方法中才可以
             * */
            DoValue d = new DoValue();
            //按引用内存地址传参
            d.na(ref a, ref b);
            //可直接打印,不需要在这里赋值,因为内存地址的数据变了
            Console.WriteLine(a);
            Console.WriteLine(b);
            //
            //
            //按输出传递参数
            d.getValus(out a, out b);
            Console.WriteLine(a);
            Console.WriteLine(b);
        }

        //按引用内存地址传参,前提:参数必须是非常量,即不允许加const关键字
        private void na(ref int a, ref int b)
        {
            int temp;
            temp = a;
            a = b;
            b = temp;
        }

        //按输出传递参数
        private void getValus(out int a, out int b)
        {
            a = 100;
            b = 200;
        }
    }
}

3.测试

控制台打印

原文地址:https://www.cnblogs.com/c2g5201314/p/13577183.html