CS1501 C# No Overload for method takes 2 Arguments

Asked

Viewed 141 times

1

I’m starting to venture into C#, but I’m getting the bug

"CS1501 C# No Overload for method takes 2 Arguments"

The code is very simple and probably contains no error, because I am using the code made available (via download) by the author of the book I am following, as below.

Code:

namespace ClassDemo  
{  
    class Staff  
    {  
        private string nameOfStaff;  
        private const int hourlyRate = 30;  
        private int hWorked;  
        public int HoursWorked  
        {  
            get  
            {  
                return hWorked;  
            }  
            set  
            {
                if (value > 0)
                    hWorked = value;
                else
                    hWorked = 0;
            }
        }

        public void PrintMessage()
        {
            Console.WriteLine("Calculating Pay...");
        }

        public int CalculatePay()
        {
           PrintMessage();

            int staffPay;
            staffPay = hWorked * hourlyRate;

            if (hWorked > 0)
                return staffPay;
            else
                return 0;
        }

        public int CalculatePay(int bonus, int allowance)
        {
            PrintMessage();

            if (hWorked > 0)
                return hWorked * hourlyRate + bonus + allowance;
            else
                return 0;
        }

        public override string ToString()
        {
            return "Name of Staff = " + nameOfStaff + ", hourlyRate = " + hourlyRate + ", hWorked = " + hWorked;
        }

        public Staff(string name)
        {
            nameOfStaff = name;
            Console.WriteLine("\n" + nameOfStaff);
            Console.WriteLine("--------------------------");
        }

        public Staff(string firstName, string lastName)
        {
            nameOfStaff = firstName + " " + lastName;
            Console.WriteLine("\n" + nameOfStaff);
            Console.WriteLine("--------------------------");
        }

    }

    class Program
    {
        static void Main(string[] args)
        {
            int pay;

            Staff staff1 = new Staff("Peter");
            staff1.HoursWorked = 160;
            pay = staff1.CalculatePay(1000, 400);
            Console.WriteLine("Pay = {0}", pay);

            Staff staff2 = new Staff("Jane", "Lee");
            staff2.HoursWorked = 160;
            pay = staff2.CalculatePay();
            Console.WriteLine("Pay = {0}", pay);

            Staff staff3 = new Staff("Carol");
            staff3.HoursWorked = -10;
            pay = staff3.CalculatePay();
            Console.WriteLine("Pay = {0}", pay);

            Console.Read();
        }
    }
}
  • Solved the problem?

1 answer

1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.