利用泛型与委托拓展冒泡排序
冒泡排序一般只适用于一些可直接比较大小的单个值,如果遇到比较对象数组中某一个属性,对对象数组中的元素进行排序,就显得不适用了,例如有一组学生对象,将他们存入数组中,比较他们中的分数来将该对象数组进行冒泡排序,这时就需要利用泛型与委托来实现。
以下是代码部分:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _001_泛型与委托_冒泡排序拓展
{
/// <summary>
/// 学生类
/// </summary>
class Student
{
//属性姓名
public string Name { get; private set; }
//属性分数
public int Record { get; private set; }
//构造函数
public Student(string name, int record)
{
this.Name = name;
this.Record = record;
}
//比较方法
public static bool Compare(Student s