Method Output Lesson 4: Help

Can someone please explain to me the solution to the exercise for this lesson (Method Output Lesson 4). I have no clue what to do after step 2 :frowning:

Any help is appreciated, possibly a step by step walkthrough of the code would be very helpful!

Thank you!

Hello, @vaguegrlwants2learn.

Could you post the code you have so far? (The code you wrote for step 1 and step 2.)
A link to the exercise would also be helpful.

using System;

namespace OutParameters
  class Program
    static void Main(string[] args)
      string ageAsString = "102";
      string nameAsString = "Granny";

      int ageAsInt;
      bool outcome;
      outcome = Int32.TryParse(ageAsString, out int ageAsInt);

The above is what I have so far, I am on step two. I am getting an error after this step. “A local variable or function named ‘ageAsInt’ is already defined in this scope.” I am not sure what it means and I cant figure out what I’m doing wrong.

The link to this exercise is here:

Thank you! :slight_smile:

The error is telling you that you are trying to declare a variable that has already been declared. Here you declare ageAsInt:

Here, you declare it again:

If you leave the int out of the above statement, you are referring to the previously declared variable rather than declaring it a second time. The other option would be to delete the previous declaration, and declare it as you have here in the out parameter. I think the exercise wants you to keep the original declaration, and use the original variable in the out parameter.

Also, FYI, to make it easier for others to read your code, and offer assistance, you can retain your code’s original formatting by placing it between otherwise empty lines that have 3 back ticks on them:

code goes here

See How do I format code in my posts? for more information.

1 Like