Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix "No overload for method ' ' takes 0 arguments"?

How can I fix this error?

"No overload for method 'output' takes 0 arguments".

The error is at the very bottom at "fresh.output();".

I don't know what I'm doing wrong. Can someone tell me what I should do to fix the code?

Here is my code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication_program
{
    public class Numbers
    {
        public double one, two, three, four;
        public virtual void output(double o, double tw, double th, double f)
        {
            one = o;
            two = tw;
            three = th;
            four = f;
        }
    }
    public class IntegerOne : Numbers
    {
        public override void output(double o, double tw, double th, double f)
        {
            Console.WriteLine("First number is {0}, second number is {1}, and third number is {2}", one, two, three);
        }
    }
    public class IntegerTwo : Numbers
    {
        public override void output(double o, double tw, double th, double f)
        {
            Console.WriteLine("Fourth number is {0}", four);
        }
    }
    class program
    {
        static void Main(string[] args)
        {
            Numbers[] chosen = new Numbers[2];

            chosen[0] = new IntegerOne();
            chosen[1] = new IntegerTwo();

            foreach (Numbers fresh in chosen)
            {
                fresh.output();
            }     
            Console.ReadLine();
        }
    }
}
like image 879
User Avatar asked Oct 22 '13 12:10

User


People also ask

What does no overload for method mean?

No overload for method 'method' takes 'number' arguments. A call was made to a class method, but no definition of the method takes the specified number of arguments.

How do I fix CS1501?

The error CS1501 is resolved by ensuring that the correct number of arguments are being passed into the method being invoked.


2 Answers

It's telling you that the method "output" needs arguments. Here's the signature for "output":

public override void output(double o, double tw, double th, double f)

So if you want to call that you need to pass in four doubles.

fresh.output(thing1,thing2,thing3,thing4);

Or to use hard coded values as an example:

fresh.output(1,2,3,4);
like image 162
Bill Gregg Avatar answered Nov 15 '22 00:11

Bill Gregg


There's no method named output that takes 0 arguments, there's only one that accepts 4 arguments. You must pass parameters to output():

foreach (Numbers fresh in chosen)
{
    fresh.output(o, tw, th, f);
}
like image 20
Chris Mantle Avatar answered Nov 14 '22 22:11

Chris Mantle