求救

sky_rv 2011-11-13 02:06:26
using System;
using System.Collections.Generic;
using System.Text;

namespace DelegetFrom
{


class BubbleSorter
{
public static void Sort(object [] sortArray, CompareOP op)
{
for (int i = 0; i < sortArray.Length; i++)
{
for (int j = 0; j < i; j++)
{
if (op(sortArray[i], sortArray[j]))
{
object temp = sortArray[i];
sortArray[i] = sortArray[j];
sortArray[j] = (Employee)temp;
}
}

}
}

}

class Employee
{
string name;
int salary;

public Employee(string n, int s)
{
this.name = n;
this.salary = s;
}

public override string ToString()
{
return this.name;

}


public static bool CompareDelegate(object lhs, object rhs)
{
Employee lhsEmp = (Employee)lhs;
Employee rhsEmp = (Employee)lhs;

return (rhsEmp.salary > lhsEmp.salary) ? true : false;



}
}

delegate bool CompareOP(object lhs, object rhs);
class Program
{
static void Main(string[] args)
{

Employee[] employee ={

new Employee("sikewe",0),
new Employee("zhouhongyan",100),
new Employee("s",50000),
new Employee("z",0)

};

CompareOP employeeOp = new CompareOP(Employee.CompareDelegate);
BubbleSorter.Sort(employee, employeeOp);

for (int i = 0; i < employee.Length; i++)
{
Console.WriteLine(employee[i].ToString());
}

Console.Read();
}
}

}


求解怎么没排序呢、、、谢谢。。帮忙看看 各位
...全文
63 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
sky_rv 2011-11-13
  • 打赏
  • 举报
回复
哦。。谢了,,
qgqch2008 2011-11-13
  • 打赏
  • 举报
回复
Employee rhsEmp = (Employee)rhs;
qgqch2008 2011-11-13
  • 打赏
  • 举报
回复
            public static bool CompareDelegate(object lhs, object rhs)
{
Employee lhsEmp = (Employee)lhs;
Employee rhsEmp = (Employee)rhs;//你这里写错了
return (rhsEmp.salary > lhsEmp.salary) ? true : false;
}

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧