FAQ: Method Output - Review

This community-built FAQ covers the “Review” exercise from the lesson “Method Output”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn C#

FAQs on the exercise Review

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!
You can also find further discussion and get answers to your questions over in #get-help.

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head to #get-help and #community:tips-and-resources. If you are wanting feedback or inspiration for a project, check out #project.

Looking for motivation to keep learning? Join our wider discussions in #community

Learn more about how to use this guide.

Found a bug? Report it online, or post in #community:Codecademy-Bug-Reporting

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

Hey! Just a quick question, (probably me missing something obvious!) but in this exercise, I get the error message in the terminal saying “Program.cs(19,25): error CS0165: Use of unassigned local variable ‘welcomeMessage’ [/home/ccuser/workspace/csharp-review-method-output/c-sharp-hello-world-run-some-c-sharp.csproj]”. However, welcomeMessage has been defined and assigned in the script:

string welcomeMessage;
welcomeMessage = DecoratePlanet(destination);

Why do I get this error message? Is it because I am assigning a variable using a method rather than directly?

Thank you in advance!

The hardest part this lesson was out.
Let me practise:

using System; namespace MyProgram { class Program { static void Main(string[] args) { Console.WriteLine(Returner(1, out int num2, out int num3)); Console.WriteLine(num2); Console.WriteLine(num3); } static int Returner(int number1, out int number2, out int number3) { int number2 = 2; int number3 = 3; return number1; } } }

Why is there an error?

You are declaring variables that have already been declared:

static int Returner(int number1, out int number2, out int number3) //number2 and number3 are declared here
      int number2 = 2; //and here
      int number3 = 3; //and here
      return number1;

Reading the text of the error message helps. If you tried the code outside of the Codebyte above that is. The Codebyte doesn’t provide the error message. The message says:

error CS0136: A local or parameter named ‘number2’ cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter

There’s also an identical message regarding number3.

The out variables need to be assigned to values inside the method, but should not be re-declared.


What you are doing is similar to this:

int blah = 5;
int blah = 7;

The above throws this error:

error CS0128: A local variable or function named ‘blah’ is already defined in this scope

What you want would be similar to:

int blah = 5;
blah = 7; //reassignment
1 Like