posts - 206,  comments - 26,  views - 17万
< 2025年2月 >
26 27 28 29 30 31 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 1
2 3 4 5 6 7 8
复制代码
   class Program
    {
        static void Main(string[] args)
        {
            //int[] arr = new int[3];
            //TestParams(arr);
            //int[] arr = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
            ////  TestParams(arr); 
            //int[] a = new int[0];
            //TestParams(1, 2, 3, 4, 5); 

            //int i = 12;
            //TestOut(out i);
            //Console.WriteLine(i);

            //int[] arr = { 1, 2, 5, 4, 3 };
            //int min = 0;
            //int max = 0;
            //GetMaxAndMin(arr, out max, out min);
            //Console.WriteLine(min+":"+max);

            int num=0; 
            TestRef(ref num);
            Console.WriteLine(num);
            //TestOut(out num); 
            //Console.WriteLine(num);

          

            Console.ReadKey();
        }


        //在同1个作用域下 不能定义相同名字的成员.
        //什么情况下可以构成方法重载:
        //1. 方法的名字一样 2.方法参数的个数或者类型或者顺序不一样 3.必须在同1个类中. 4.与返回值无关.
        //可变参数 参数被params修饰 params只能用来修饰1维数组
        //给可变参数赋值的时候 可以直接传递数组的元素.
        //在调用的时候 会自动的将这些元素封装为1个数组 并将数组传递.
        //可变参数必须放在参数列表的最后. 
        //ref 修饰方法的参数  在调用的时候必须在变量前面加上ref关键字. 只能传递变量不能传递常量.
        //传递的时候 不是传递变量的值 而是传递变量的地址.
        //out 也是传递的变量的地址.out必须在方法内为其赋值.ref可以修改其值也可以不修改.
        //out侧重于输出 ref侧重于修改. 
        //out在传递之前可以不赋初始值 因为在方法中肯定会为out赋值.
        //ref 在传递之前必须要有值 因为在方法中有可能会用到这个参数的值.


        static void TestOut(out int i)
        {
            string str = "s";
            if (str == "s")
            {
                i = 1;
            }
            else
            {
                i = 2;
            } 
        } 

        static void TestRef(ref int i)
        {
            i = i + 1;
           
        }

         //冒泡排序
        static void GetMaxAndMin(int[] arr, out int max, out int min)
        { 
            for (int i = 0; i < arr.Length - 1; i++)
            {
                for (int j = 0; j < arr.Length - 1 - i; j++)
                {
                    if (arr[j] > arr[j + 1])
                    {
                        int temp = arr[j];
                        arr[j] = arr[j + 1];
                        arr[j + 1] = temp;
                    }
                }
            }
            max = arr[arr.Length - 1];
            min = arr[0];
        }



        //static void TestParams(int i, int j, params int[] arr)
        //{

        //} 

        static void Test(int i, string str)
        {

        }

        static void Test()
        {
            Console.WriteLine("B");
        }
    }
复制代码

 

posted on   努力--坚持  阅读(270)  评论(0编辑  收藏  举报
(评论功能已被禁用)
编辑推荐:
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
阅读排行:
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
· 上周热点回顾(2.17-2.23)
点击右上角即可分享
微信分享提示