No overload for method 'alphaFunction' takes '0' arguments

Good afternoon expert,

I am trying to learn some C# basic concepts. I put together this console program that works, marked program works below. The out put is
text in alphaFunction
text in alphaFunction
bravo function text
I then tried an passing the 'text alphaFunction' to the alphaFunction using a parameter in the code  
marked 'No overload for method 'alphaFunction' takes '0' arguments' below and got the error message.

I think the call
two_functions_class_alpha.alphaFunction();
does not see the parameter being passed. But
the strVar is passed to the alphaFunction
when it is opened why does it not see the
parameter when it si called in Main.

Also some texts called MAin a function others call it a method.
Which is correct?

Thanks.

Allen in Dallas






Program works ****************************************************************
class two_functions_class_alpha
{  // open two_functions_class_alpha
      static void Main()
      { // open function Main
            two_functions_class_alpha.alphaFunction();
            alphaFunction();
            two_functions_class_bravo.bravoFunction();
      }  //close function Main
      public static void alphaFunction()
      {  //open alphaFunction
            System.Console.WriteLine("text in alphaFunction");
      }   //close alphaFunction
}  // close two_functions_class_alpha
class two_functions_class_bravo
{ //open two_functions_class_bravo
      public static void bravoFunction()
      { //open bravoFunction
            System.Console.WriteLine("bravo function text");
      }  //close bravoFunction
} // close two_functions_class_bravo

'No overload for method 'alphaFunction' takes '0' arguments' ******************************************
class two_functions_class_alpha

{  // open two_functions_class_alpha

      static void Main()

      { // open function Main

            two_functions_class_alpha.alphaFunction();

            alphaFunction("text in alphaFunction");

            two_functions_class_bravo.bravoFunction();

      }  //close function Main

      public static void alphaFunction(string strVar)

      {  //open alphaFunction

            System.Console.WriteLine("{0}", strVar);

      }   //close alphaFunction

}  // close two_functions_class_alpha

class two_functions_class_bravo

{ //open two_functions_class_bravo

      public static void bravoFunction()

      { //open bravoFunction

            System.Console.WriteLine("bravo function text");

      }  //close bravoFunction
 

} // close two_functions_class_bravo



Allen PittsBusiness analystAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

bobbit31Commented:
Hello 9apit,

you have to actually declare / define the function you are overloading.

for example, if you were to have two overloads for alphaFunction:

public static void alphaFunction()
{
   // do something here
}

AND

public static void alphaFunction(string strVar)
{
   // do something here as well
}

so you would have something like:

class two_functions_class_alpha

{  // open two_functions_class_alpha

      static void Main()

      { // open function Main

            two_functions_class_alpha.alphaFunction();

            alphaFunction("text in alphaFunction");

            two_functions_class_bravo.bravoFunction();

      }  //close function Main

      public static void alphaFunction()
      {  //open alphaFunction
            alphaFunction("alphaFunction called w/ 0 parameters");
      }   //close alphaFunction


      public static void alphaFunction(string strVar)

      {  //open alphaFunction

            System.Console.WriteLine("{0}", strVar);

      }   //close alphaFunction

}  // close two_functions_class_alpha


Regards,

bobbit31
0
Allen PittsBusiness analystAuthor Commented:
Hello bobbit31,

First, I am blown away by the rapidness of your answer. Amazing!

Second, I  don;t think I understand it. Rememeber I am just getting started. I think
by 'overload you mean to call a function with a different number of paarmeters than
the number of parameters given when the function or method (what is the correct term?)
is defined. So I tried passing the parameter to the call of
two_functions_class_alpha.alphaFunction(string strVar);
this results in error 'invalid expression term 'string'
So I took 'string' out. Since strVar is denied in the  declaration of alphaFunction
perhaps we only need the name of the parameter. But this resullts
'The name 'strVar' does not exist in the class or namespace 'two_functions_class_alpha'
To wit if I comment out the statement
            two_functions_class_alpha.alphaFunction();
the code works.  Is there no way toalter ther statement to make it work?
I think perhaps it is the placement of the statement.

0
bobbit31Commented:
function overloading is simply a way to have 2 or more functions have the same name which are distinguished either by number of parameters and/or parameter types...

anyway,

two_functions_class_alpha.alphaFunction(string strVar);

is simply an invalid statement... you are calling the function, not defining it.

two_functions_class_alpha.alphaFunction(strVar);

doesn't work b/c strVar isn't declared... try something like:

string strVar = "Hello World";
two_functions_class_alpha.alphaFunction(strVar);

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SwissKnifeCommented:
Hello
Your are calling a functio that does not exist. The compiler is lookin for a function alphaFunction that takes no arguments. You have declared a function with one argument, a string.

You can call the this function with one argument e.g. alphaFunction( "Hello" ).

Or you can declare a second function with no argumets as bobbit31 shows.
0
Allen PittsBusiness analystAuthor Commented:
I see now that the definition of the variable as parameter in the function statement did not provide a definition of the varuibale in the Main method.
It could be that you are so expertat C# that is difficult for you to imagine that mind set of a novice.
Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.