+ 2

How to identify type of input read from the keyboard in C# ?

if the input is given as '2' or such then it should print it as integer and if string then to print as string

10th Aug 2018, 1:25 PM
Subramanya
Subramanya - avatar
3 Antworten
+ 3
You can convert the input to an integer int.parse(Console.Read()) .. output is read as a string
10th Aug 2018, 2:41 PM
John
John - avatar
+ 3
use int.TryParse(), it will try to parse it as an integer but if it fails you can just assign it as a string and you wont have to do any exception handling
10th Aug 2018, 2:56 PM
hinanawi
hinanawi - avatar
0
I think you can use regular expression to define several templates to match many data types such as integer, real number, complex number, telephone number :-D, string, or more specifically string like email address, proper names, etc.
12th Aug 2018, 1:31 PM
Rocky Lee
Rocky Lee - avatar