using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace learn_function
{
    internal class Program
    {
        // 参数数组
        static void AAA(string aaa, params int[] bbb)
        {
            Console.WriteLine(aaa);
            Console.WriteLine(bbb);
        }

        // 引用参数
        static void BBB(ref int aaa, int[] bbb)
        {
            aaa++;
            bbb[0] = 3;
        }

        // 输出参数
        static void CCC( int aaa, out int bbb)
        {
            aaa++;
            bbb = aaa;
        }

        // return多个值
        static Tuple<int, int> DDD(int aaa, int bbb)
        {
            int ccc = aaa;
            aaa = bbb;
            bbb = ccc;
            return new Tuple<int, int>(aaa, bbb);
        }

        static void Main(string[] args)
        {
            // 参数数组
            AAA("abc", 1, 2, 3);

            // 引用参数
            int a = 1;
            int[] c = { 1, 2, 3 };
            // 引用参数后不需要返回,传入的参数直接就变了; 列表在函数中默认就是引用参数
            BBB(ref a,c);
            Console.WriteLine($"{a}");
            for (int i = 0; i < c.Length; i++)
            {
                Console.WriteLine(c[i]);
            }

            // 输出参数
            int b = 1;
            int d;
            CCC(b,out d);
            Console.WriteLine(d);

            // 使用函数输出元组
            var e = DDD(111,222);
            Console.WriteLine(e);
            Console.ReadKey();
        }
    }
}

输出

abc
System.Int32[]
2
3
2
3
2
(222, 111)
posted on 2023-01-15 22:25  盈盈的月儿  阅读(50)  评论(0编辑  收藏  举报