本文介绍了BubbleSort错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Error 1 The best overloaded method match for 'Project_210.BubbleSorter.Sort(object[], Project_210.CompareOp)' has some invalid arguments C:\Documents and Settings\Eddy Ho\Local Settings\Application Data\Temporary Projects\Project-210\Program.cs 67 13 Project-210
Error 2 Argument '2': cannot convert from 'Project_210.Program.CompareOp' to 'Project_210.CompareOp' C:\Documents and Settings\Eddy Ho\Local Settings\Application Data\Temporary Projects\Project-210\Program.cs 67 42 Project-210
using System;
using System.Collections.Generic;
using System.Text;
namespace Project_210
{
delegate bool CompareOp(object lhs, object rhs);
class BubbleSorter
{
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;
}
}
}
}
}
class Employee
{
private string name;
private decimal salary;
public Employee(string name, decimal salary)
{
this.name = name;
this.salary = salary;
}
public override string ToString()
{
return string.Format(name + " {0:C)", salary);
}
public static bool RhsIsGreater(object lhs, object rhs)
{
Employee empLhs = (Employee)lhs;
Employee empRhs = (Employee)rhs;
return (empRhs.salary > empLhs.salary) ? true : false;
}
}
class Program
{
delegate bool CompareOp(object ihs, object rhs);
static void Main(string[] args)
{
Employee[] employees =
{
new Employee("Karli Watson",20000),
new Employee("Bill Gates",10000),
new Employee("Simon Robinson",25000),
new Employee("Mortime",(decimal)100000),
new Employee("Arabe Jones",20000),
new Employee("Avon from <code>'</code>;Black's 7'",50000)
};
CompareOp employeeCompareOp = new CompareOp(Employee.RhsIsGreater);
BubbleSorter.Sort(employees, employeeCompareOp);
for (int i = 0; i < employees.Length; i++)
Console.WriteLine(employees[i].ToString());
}
}
}
推荐答案
这篇关于BubbleSort错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!