+ 1
C# How to check if the user's input is number(not a text or empty)?
Hi! I made a working code, and I stuck with the validation of the user's input. Here is my code(please see the "if" condition under highlighted string): https://pastebin.com/5pRgezSm
2 Respostas
+ 2
Use Double.TryParse method, it returns true if an expression passed as argument can be safely converted into a Double type.
https://docs.microsoft.com/en-us/dotnet/api/system.double.tryparse
+ 1
Depending on if you mean int or float by "number", you can use these codes(str is user input) :
int.TryParse(str)
or
float.TryParse(str)
both statements return true if string is a number, else they'll return false.