FAQ: Method Output - Using Out

This community-built FAQ covers the “Using Out” 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 Using Out

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!

using System;

namespace UsingOut
{
  class Program
  {
    static void Main(string[] args)
    {
      string statement = "GARRRR";
      Whisper(statement, out bool marker);
    }    
    static string Whisper(string statement, out bool isCalled) {
      isCalled = true;
      return statement.ToLower();
    }
	}
}

1 Like

Hello,

Please excuse eventual mistakes that could explain why I don’t get this exercise.

First of all, when I call the method Whisper, the out bool marker <- I’m not sure what this marker is or where it comes from, but maybe that is part of my problem.

In step 3:

3.

Call Whisper() in the Main() method and print the returned value to the console.

Make sure to use an out modifier when calling the method!

This part here: I don’t know what I’m supposed to print. What is the returned value in this case?

Here is my code:

using System;

namespace UsingOut
{
class Program
{
static string Whisper(string phrase, out bool didYouWhisper)
{
didYouWhisper = true;
return phrase.ToLower();
}
static void Main(string args)
{
string phrase = “WIENERBROOOOEEEEED!”;
Whisper(phrase, out bool marker);
Console.WriteLine(phrase);
}

}

}

Replying to my own post here: I think I figured it out, is this what it means to print the returned value to the console?

image

2 Likes

Hope this helps. EDIT* just saw that you figured it out on your own.

1 Like

@ tochmy and @ ilijada

I got confused with this excercise (the “flag” part wasn’t so clear during the lesson, but figured it out eventually). With regards to the two examples above, I thought maybe others might share my confusion.

I can’t get tochmy’s example example to run (also it doesn’t make sense to me if it does, since the alias-variable you use inside the method is not available outside of the method - the value has to be stored in a variable in the calling method if you are to print it from the calling method?).

In ilijada’s example the value is stored in a new variable inside the calling method, so that runs fine. But I thought I’d just share the way to do it without creating a new variable (store it in the original one).
I think it’s less confusing like that - you are not in doubt what variable you have modified with your method. (Sorry if this is old news to everyone, it took me a while to realise that it’s allowed to reuse the variables :sweat_smile: )

//MAIN METHOD
 static void Main(string[] args)
      {
        string myVariable = "AAARGH!";
//store the modified data in myVariable:
        myVariable = Whisper(myVariable, out bool wasWhisperCalled);
        Console.WriteLine(myVariable);
      }  
//MY METHOD
static string Whisper(string myAlias,       out bool wasWhisperCalled)
      {
      wasWhisperCalled = true;
      return myAlias.ToLower();
      }

After failing a couple of times I managed to get this working :^)

using System;

namespace UsingOut
{
  class Program
  {
    static void Main(string[] args)
    {
      string statement = "KEEP QUIET, YOUNG MAN, THIS IS A LIBRARY";
      Whisper(statement, out bool scolded);
      Console.WriteLine(Whisper(statement, out scolded));
    } 
   
    static string Whisper(string statement, out bool scolded)
    {
      scolded = true;
      return statement.ToLower();
    }
	}
}