泛型中不能直接比较,要用where T :IComparable
而且静态类中不能传递出来结果。。只能在静态类的内部输出结果。
1:比较和排序的概念
比较:两个实体类之间按>,=,<进行比较。
排序:在集合类中,对集合类中的实体进行排序。排序基于的算法基于实体类提供的比较函数。
基本型别都提供了默认的比较算法,如string提供了按字母进行比较,int提供了按整数大小进行比较。
2:IComparable和IComparer
当我们创建了自己的实体类,如Student,默认想要对其按照年龄进行排序,则需要为实体类实现IComparable接口。
可使用IComparer来实现一个自定义的比较器。
3:IComparable和IComparer的泛型实现IComparable<T>和IComparer<T>
具体见:http://www.cnblogs.com/luminji/archive/2010/09/30/1839038.html
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{