• 例题:函数输出参数。理解函数的作用,函数是一个相对独立的代码块


    class Program
        {
            public  int[] shuchucanshu(int[] shu,out int a,out int b) //基本格式,定义一个int数组
            {
                for (int i = 0; i < shu.Length ; i++) //冒泡排序
                {
                    for (int j = i; j < shu.Length -1; j++)
                    {
                        if (shu[i]<shu[j+1])
                        {
                            int zhong = 0;
                            zhong = shu[i];
                            shu[i] = shu[j + 1];
                            shu[j + 1] = zhong;
                        }
                    }
                }
                a = shu[0]; //最大值
                b = shu[shu.Length - 1];//最小值。排序已经拍好,[shu.Length - 1]是最小数的下标
              
                return shu;
            }
            static void Main(string[] args)
            { 
                int a,b; //声明,与函数里的a,b没有任何关系,函数是独立的代码块
                int[] shu=new int[5]{1,3,5,9,6};
                new Program ().shuchucanshu (shu,out a,out b); //调用函数
                for (int i = 0; i < shu.Length ; i++)
                {
                    Console.WriteLine(shu[i]);
                }
                Console.WriteLine("最大值是"+a+",最小值是"+b);
                Console.ReadLine();
            }

  • 相关阅读:
    table 如何不越过父级div
    sqlite3_column_type 与 SQLITE_NULL的区别
    lua 协程的理解
    linux 信号
    linux 查看文件夹大小
    linux 僵屍进程
    软件架构的理解
    jquery正则表达式
    linux C遍历目录下文件
    linux 进程间同步互斥
  • 原文地址:https://www.cnblogs.com/275147378abc/p/4428849.html
Copyright © 2020-2023  润新知