函数版5个数的升序降序

来源:互联网 发布:软件服务行业 编辑:程序博客网 时间:2024/05/21 08:41
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace ConsoleApplication56
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] a = new int[5] { 3, 2, 6, 8, 9 };//定义数组并进行初始化
            OutPut(a);//调用函数
            ArraySort(a,0);//
            OutPut(a);
            ArraySort(a, 1);//对数组进行升序
            OutPut(a);//对数组进行降序
           
            Console.ReadKey();


        }


        static void OutPut(int[] array)//定义函数类型:int 名称:OutPut 
        {
            foreach (int iten in array)//遍历数组
            {
                Console.Write(iten+"  ");//
               
            }
        
        
        }


        static void ArraySort(int[] array,int s)
        {
            
            Array.Sort(array);
            if (s == 1) Array.Reverse(array);
       Console.WriteLine(); 
        } 
        
    }




}


注释错的话,请帮忙指出。

0 0
原创粉丝点击