using System;
using System.Collections.Generic;
using System.Text;
namespace 委托
{
class Program
{
public delegate void SortDelegate(int[] SortArray);
static void Main(string[] args)
{
//Del handler = new Del(Show);
//handler("委托给Show");
//MethodWithCallBack(1, 5, handler); //异步回调
SortDelegate Sort;
int[] a = new int[5] { 81, 45, 23, 105, 90 };
Console.WriteLine("请输入排序方法");
string str = Console.ReadLine();
if (str == "升序")
{
Sort = new SortDelegate(AscSort);
}
else
{
Sort = new SortDelegate(DescSort);
}
Sort(a);
foreach (int x in a)
{
Console.WriteLine(x);
}
}
public static void AscSort(int[] array) //升序排列
{
for (int i = array.Length - 1; i >= 1; i--)
{
for (int j = 0; j < i; j++)
{
if (array[j] > array[j + 1])
{
int m = array[j];
array[j] = array[j + 1];
array[j + 1] = m;
}
}
}
}
public static void DescSort(int[] array)
{
for (int i = array.Length - 1; i >= 1; i--)
{
for (int j = 0; j < i; j++)
{
if (array[j] < array[j + 1])
{
int m = array[j];
array[j] = array[j + 1];
array[j + 1] = m;
}
}
}
}
}
}