public static bool RhsIsGreater(object lhs, object rhs)
{
Employee empLhs = (Employee) lhs;
Employee empRhs = (Employee) rhs;
return (empRhs.salary > empLhs.salary) ? true : false;
}
{
Employee empLhs = (Employee) lhs;
Employee empRhs = (Employee) rhs;
return (empRhs.salary > empLhs.salary) ? true : false;
}
也就是说RhsIsGreater的参数是匹配CompareOp存在的,参数中没有直接使用Employee这个type而是采用了一种通用的做法,全都弄成object需要的时候再做转换,暂时还无法理解其深远的意义,先记着了。估计是定义委托时不能用这些自定义的type吧。
那么这段代码是什么时候运行的呢,注意看这段
static public void Sort(object [] sortArray, CompareOp gtMethod)
{
for (int i=0 ; i<sortArray.Length ; i++)
{
for (int j=i+1 ; j<sortArray.Length ; j++)
{
if (gtMethod(sortArray[j], sortArray[i]))
{
object temp = sortArray[i];
sortArray[i] = sortArray[j];
sortArray[j] = temp;
}
}
}
}