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);
}

}

}

1 Like

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

3 Likes

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

3 Likes

@ 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();
    }
	}
}

using System;

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

Can someone tell me why the left side of the screen says this is correct, but the terminal won’t print it and instead says error?

Do you need to declare that phrase is a string in the method call?

You need to call the method in the Console.WriteLine() statement after calling it the first time without an assignment statement.

This should be sufficient:

      Console.WriteLine(Whisper(statement, out scolded));

Hey guys,

After I couldnt understand what is going on here, I used the “View Solution” button…though I am not sure if I ve understood it now…

Nevertheless, I dont understand why the solution is printing “garrrr” on the console. In my humble opinion its wrong, though I would rather say I dont understand…

The method “Whisper” is declared by the string “phrase”…“phrase” is also being returned. So far so good…

Under method Main() “murmur” calls Whisper with the parameter “statement”. My question is: Where is the link between statement and phrase??

What also works if you exchange the “statement” by “phrase”…this is what I ve done and what seemed reasonable for me…

Now, I am I missing something ?

Thanks in advance for sharing your knowledge and opinions with me!

using System;

namespace UsingOut

{

class Program

{

static void Main(string[] args)

{

  string statement = "GARRRR";

  string murmur = Whisper(statement, out bool marker);

  Console.WriteLine(murmur);

}  



static string Whisper(string phrase, out bool wasWhisperCalled) 

{

  wasWhisperCalled = true;

  return phrase.ToLower();

}

}

}

What did you expect the output to be, if not garrrr? What does phrase.ToLower() do?

What also works if you exchange the “statement” by “phrase”…this is what I ve done and what seemed reasonable for me…

That is correct. You sent the arguments statement and marker which correspond to parameters phrase and wasWhisperCalled.

This is what I came up with:

using System;

namespace UsingOut
{
  class Program
  {
    static void Main(string[] args)
    {
      string statement = "GARRRR";
      string lowStatement = Whisper(statement, out bool marker);
      Console.WriteLine(lowStatement);
      Console.WriteLine(marker);

      // returns "garrrr" and marker is true
      
    }   
    static string Whisper(string word, out bool question)
    {
      question = true;
      return word.ToLower();
    }
	}
}

Works like a charm!

1 Like

Can someone please help explain the whole concept of out in simpler words? It’s really confusing me.

3 Likes

You are declaring a string that was already declared. Just leave out the datatype.

Console.WriteLine(Whisper(phrase, out bool wasWhispered));

Also left side of the screen can’t tell you if anything is correct, the program has to run in order for errors to be written out on a terminal (right side).

I don’t get this exercise. May someone explain it to me.

1 Like

Thanks for the heads up. I was wondering how come my bool answer was not printed out together with the statement. Looks like we need to print it out individually, which is kinda weird as I thought it would print out together. Looks like I need to research more on this topic.

I’ve been reading a couple of the questions posed here and do understand where the confusion comes from when it comes to having seemingly two completely different parameters. To maybe clarify what I meant with the confusion; People seem to think that “statement” and “phrase” are two different things while they’re “statement” in this case is just a placeholder for “phrase”.

However the thing that troubled me most was why, in this particular case, you’d even use the out method we’re being taught. I fail to see the correlation between it since we’re not asked to print it to the console. Like in the previous exercise…

Can somebody please explain, the purpose of the boolean in the Whisper method if this value can’t be passed to the main? Thank you.

2 Likes

using System;

namespace UsingOut

{

class Program

{

static void Main(string[] args)

{

  Console.WriteLine(Whisper(stringName: "Hello My Friend", out bool boolName));

}

static string Whisper(string stringName, out bool boolName)

{

  boolName = true;

  return stringName.ToLower();

}

}

}

1 Like