Question
For C# Write a static method named GetChar(), which uses a reference parameter to accept a character argument. The method should prompt the user to
For C#
Write a static method named GetChar(), which uses a reference parameter to accept a character argument. The method should prompt the user to enter a character and validate to make sure the character entered is between 'A' to 'F'. The input should be stored in the parameter variable.
You do not need to write entire program, only the definition of the method and method call. Use the following example as guide line.
//To write a static method which uses a reference parameter to accept an integer argument. The method should prompt the user to enter an integer and validates to make sure the integer entered is between 0 and 100 inclusive. The input should be stored in the parameter variable.
static void getNumber(ref int num) { Console.Write("Enter an integer between 0 and 100:"); string input = Console.ReadLine(); while (int.TryParse(input, out num) == false || num < 0 || num > 100) { Console.Write("Invalid input, enter again:"); input = Console.ReadLine(); } }
// Method call
int number = 0; getNumber(ref number);
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started