冒泡排序,使用泛型,委托
using System;
public class Program
{
public static void Main()
{
int[] amt =new int[]{10,20,60,40,50,90,100};
MySort(amt,(a,b)=>{return a>b;});
foreach(var i in amt)
{
Console.Write(i+" ");
}
Console.WriteLine("\n"+"END");
}
public static void MySort<T>(T[] arr,Func<T,T,bool> compare)
{
for(int i =0;i<arr.Length-1;i++)
{
for(int j =i+1; j<arr.Length; j++)
{
if(compare(arr[i],arr[j]))
{
T tem = arr[i];
arr[i] = arr[j];
arr[j] = tem;
}
}
}
}
}
--------------------------------------------------------------------------------------------------------------------------------
表达抽象的语义:
抽象类:一个概念的抽象(含普通成员,和抽象成员)
接口:一组行为的抽象(多种抽象成员,很多种)
委托:一类行为的抽象(同一种类别)