zoukankan      html  css  js  c++  java
  • 例题:函数输出参数。理解函数的作用,函数是一个相对独立的代码块

    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();
            }

  • 相关阅读:
    Unity3D保护资源管理文件的AssetBundle包加密!
    untiy Kinect SDK 的默认BUG 修改方法
    Android 插件扩展系列之 封装与应用
    datagridview 单击单元格获取单元格的内容
    winform 显示动态图片 Gif
    Unity 漫游相机脚本
    Unity3D教程:c#脚本yield的用法
    Unity 脚本实现CoverFlow效果
    删除 treeview Node节点 循环删除子节点 存储过程
    Unity 怪物AI
  • 原文地址:https://www.cnblogs.com/275147378abc/p/4428849.html
Copyright © 2011-2022 走看看