0
How to get type of an input text in csharp
How to get type of an input text in csharp For example: string s = Console.ReadLine(); How to get best type of s? for example if s is ="42" output int or if s is = "hello" output string Thanks
4 Answers
+ 2
Of course there is a way. TryParse probably fits your needs best since it returns a bool. For explanation, examples and alternatives refer to this:
https://www.tutorialsteacher.com/articles/convert-string-to-int
+ 1
s will never be 42, it can only be "42", still a string. Use cast/ convert if you want something else. There is no such thing as best type in general. It depends on the application, so you have to define and implement it yourself
0
Benjamin JĂŒrgens it looks there's no way to do it?