My assignment is overloading methods, and creating a class library. When creating methods not problems till returning the out parameter. I’m not allowed to change the codes that will reference the class library.
When assigning values to the out
parameter and returning that value, I get errors.
Here’s the code:
static public int GetValue(out int iTest, string sPrompt)
{
bool bTest;
do
{
bTest = false;
Console.WriteLine(sPrompt);
try
{
iTest = int.Parse(Console.ReadLine());
}
catch (FormatException)
{
Console.WriteLine("You've entered the number incorrectly please ONLY integer value");
bTest = true;
}
}
while (bTest == true);
return iTest;
}
These are the errors I get:
CS0177 – out parameter not assigned before leaving method
CS0269 – use of unassigned out parameter
I can’t understand this because I thought Console.ReadLine
would do it.
KnightAvelli is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
7