随笔 - 63,  文章 - 0,  评论 - 4,  阅读 - 10万
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   盈盈的月儿  阅读(54)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· C#/.NET/.NET Core技术前沿周刊 | 第 29 期(2025年3.1-3.9)
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示