Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 136,251 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 2,220 people online right now. Registration is fast and FREE... Join Now!




No overload for method error

 
Reply to this topicStart new topic

No overload for method error, C# bubblesort for string

deedee66
12 Oct, 2008 - 03:10 PM
Post #1

New D.I.C Head
*

Joined: 21 Sep, 2008
Posts: 16

Hello,

I am receiving an overload error method, and i am too much of a newbie to figure out what it means. I have a toString all ready declared and it says I can not do that again. Any help will be appreciated.

the assignment was to return the employee names in alphabetical order with a bubble sort.

the first assignment was to return in salary order and I got that one no problem. But the string compare is just not working out for me.

CODE


using System;

namespace BubbleSort2
{
    class BubbleSort2
    {
        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 // : object
{
    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 (string.Compare()(empRhs.name == empLhs.name)) ? true:false;
        
    }
}
delegate bool CompareOp(object lhs, object rhs);

class bubbleSort
{
    static void Main()
    {
        Employee [] employees =
        { new Employee("Bugs Bunny", 20000),
          new Employee("Elmer Fudd", 10000),
          new Employee("Daffy Duck", 25000),
          new Employee("Wiley E. Coyote", (decimal)1000000.38),
          new Employee("Foghorn Leghorn", 23000),
          new Employee("RoadRunner", 50000)
        };
        
        CompareOp employeeCompareOp = new CompareOp(Employee.RhsIsGreater);
        BubbleSort2.Sort(employees, employeeCompareOp);
        
        for (int i=0; i<employees.Length; i++)
            Console.WriteLine(employees[i].ToString());
    }
}
}

User is offlineProfile CardPM
+Quote Post

Martyr2
RE: No Overload For Method Error
12 Oct, 2008 - 03:43 PM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,199



Thanked: 213 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
The problem is with this line...

csharp

return (string.Compare()(empRhs.name == empLhs.name)) ? true:false;


Notice that you have .Compare() but you don't put anything into it. It is saying no overload takes 0 arguments... meaning you have to supply something in that function...

Try this...

csharp

// Here we are comparing the two names for equality and empRhs is greater than empLhs then we return true, otherwise they are equal or rhs is less than lhs
return (string.Compare(empRhs.name,empLhs.name) > 0)? true : false;


That should solve the immediate problem.

"At DIC we be left hand and right hand comparing code ninjas.... I bet you your hand is bigger than your face *smack*" decap.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 04:14AM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month