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