I don’t understand what you mean by murmur/murmor?
When we make the call Whisper("GARRRR", out bool flag)
, then within the Whisper method we set wasWhisperCalled
to true. Since wasWhisperCalled
is just an alias for flag
, so flag
(which is outside the Whisper method) will be set to true as well.
However, this is not the same as using the return
keyword. The only value explicitly “returned” by the Whisper method is return phrase.ToLower();
which means that only ‘garrrr’ will be explicitly returned. wasWhisperCalled
will indeed change flag
but only one value is being explicitly returned by the method and that is lowercase phrase
. If we look at the signature of the Whisper method, we see
static string Whisper(...
that the return type is string only.
Suppose in the Main method we did something like:
// Single Line Version
Console.WriteLine(Whisper("GARRRR", out bool flag));
// The above can be broken into:
string word = "GARRRR"; // word will be GARRRR
string result = Whisper(word, out bool flag); // result will be "garrrr" and flag will be set to true
Console.WriteLine(result); // "garrrr" will be printed to the console
// After the above code, word will still be "GARRRR", result will be "garrrr", flag will be true.
// Only "garrrr" will be printed to the console.
// If we don't want to store result in some variable and only
// want to print the result, then the single line version
// accomplishes our goal without the need of declaring and initializing
// the 'result' variable.
I assume you are talking about the snippet in Step 2 of the exercise
string statement = "GARRRR";
Whisper(statement, out bool marker);
// should return "garrrr" and set marker to true;
The return value of Whisper will be the lowercased phrase
. In the above snippet, marker
will be set to true, but statement
will still be “GARRRR”. In the above snippet, nothing is done with the return value so it doesn’t accomplish anything useful other than setting marker
.
If we want to do something useful, then we could do:
string statement = "GARRRR";
// If we simply wanted to print the lowercase string
Console.WriteLine(Whisper(statement, out bool marker)); // will print "garrrr"
// If we want to replace the original statement with lowercase version
statement = Whisper(statement, out bool marker); // Now statement will be "garrrr"
// If we don't want to replace statement, we can assign lowercase version to some other variable
string myVar = Whisper(statement, out bool marker);