0

I'm having trouble converting an string to Int32 when calling it. This is what I'm struggling with.

public static int GetProgramLength()
{
    Console.WriteLine("Please enter program length:");
    return Int32.TryParse(Console.ReadLine);
}

Its telling me,

No overload for method, "Try Parse" takes 1 argument.

Arghya C
  • 9,805
  • 2
  • 47
  • 66

1 Answers1

1

You need to specify the out value to use Int32.TryParse() the result of TryParse is stored to the out parameter(outParam will be 0 if it failed to convert the input string),and also it will return a boolean value to indicate whether the conversion is success or a failure;

So you have to correct your code as like the following:

int outParam=0;
Console.WriteLine("Please enter program length:");
Int32.TryParse(Console.ReadLine(),out outParam);
return outParam;
sujith karivelil
  • 28,671
  • 6
  • 55
  • 88