Hello, I am trying out different ways to receive int number from user. If the input is not an int number, it gives out an error message.
But I seem to be getting error messages on the highlighted parts.
"Since ___________ Returns a void, a return keyword must not be followed by an object expression "
public static void FirstInput()
{
do
{
fromF = 0;
if (int.TryParse(Console.ReadLine(), out fromF))
{
return fromF;
}
Console.WriteLine("Error");
{
return FirstInput();
}
}
}
Thanks for the help!
MahaPosted Oct 19, 2014, 9:04 PM
namespace IntergerNumber
{
class Program
{
static void Main(string[] args)
{
Console.Write("Input an integer number ");
int i;
bool trueORfaulse = int.TryParse(Console.ReadLine(), out i );
outerUp:
while(trueORfaulse == false)
{
Console.Write("\nThis is not an integer number, try again ");
trueORfaulse = int.TryParse(Console.ReadLine(), out i);
}
while (trueORfaulse == true)
{
Console.Write("\nInput an integer number ");
trueORfaulse = int.TryParse(Console.ReadLine(), out i);
if (trueORfaulse == false) goto outerUp;
}
Console.ReadKey();
}
}
}
Song LeePosted Oct 23, 2014, 7:32 PM
Wim SturkenboomPosted Oct 21, 2014, 2:38 PM
You can use javascript function to check whether the input is numeric or not.
[/quote]
In a console application ??
Riddhi ValechaPosted Oct 21, 2014, 5:22 AM
You can use javascript function to check whether the input is numeric or not.
Eg-
In aspx page,
-------------------
----------------------
In this case, user will be able to type only numbers and nothing else.
Also, the lines of code will be reduced.
Wim SturkenboomPosted Oct 20, 2014, 2:02 AM
public static void FirstInput()
Change the definition to below
public static int FirstInput()