Create Methods in C# Console Applications - Write Your First C# Method

Tell us what’s happening:

Write Your First C# Method, all answers are wrong. The question is: Which of the following correctly declares a method?

  1. DisplayNumbers();
  2. void DisplayNumbers{};
  3. void DisplayNumbers() {}
    1 does not have a return type. 2 does not have parenthesis. 3 has a function body {} so it is technically a method definition (not a declaration) A correct method declaration is : void DisplayNumbers();

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:132.0) Gecko/20100101 Firefox/132.0

Challenge Information:

Create Methods in C# Console Applications - Write Your First C# Method

The decaration and definition are the same thing in C#, unlike in C

It is also MS own tests, but they do word it a bit differently (method signature vs declares a method).

  1. Suppose there’s a method named ConvertCurrency. Which of the following lines of code is a valid method signature?

I’m not an C# expert but saying void DisplayNumbers() { } is a correct method declaration doesn’t seem wrong to me.