58.8k views
9 votes
Create a method called ReadString that will ask the user for a string. Instead of returning the value like in ReadInteger, you should use pass by reference to get the string back to the caller.

1 Answer

3 votes

Answer:

public void ReadString (string inputString, ref string word)

{

Console.WriteLine(inputString);

word = Console.ReadLine();

}

Step-by-step explanation:

The C# function above is defined as a class method that accepts two arguments, the inputString and the word. The first block code outputs the string message of the first string argument, 'inputString', then the second block reads the input and assigns it to the second argument 'word'. The 'ref' keyword is used as a return statement to return the word variable.

User Zombiehugs
by
4.7k points