0
How can check the input if it was "int or string " in console app ?
int x; x =int.parse(Console.ReadLine()); //I wanna check if the user put int or String in Console ..
7 Answers
+ 3
string inputAge = Console.ReadLine();
try{
int age = Int32.Parse(inputAge);
}
catch(Exception e){
Console.WriteLine("Insert a Numeric Age");
}
+ 2
You will always get a String from a input.
You can convert that in a Int , float, or wathever later, but as init, it's a String.
+ 2
I will recommend you using try-catch blocks, when trying to parse the string to int, so it doesn't break your app.
There is a lesson in c# course here.
0
I meant that user can input for e.g: int age; input string here so it will break the app so I wanna use if to go to start if it wasn't number ..
0
can u give me an example please ?
0
thanks ! :) I appreciate it
0
x.getType();