Why can converticity type 'string' to 'int'? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why can converticity type 'string' to 'int'?

3rd Oct 2019, 6:50 AM
Alexey
Alexey - avatar
3 Answers
+ 3
I think in C#, the best way is to use Int32.TryParse() method. It gives you an option to safely handle invalid values, without writing an extra try-catch block. https://docs.microsoft.com/en-us/dotnet/api/system.int32.tryparse?view=netframework-4.8
3rd Oct 2019, 10:37 AM
Tibor Santa
Tibor Santa - avatar
+ 1
Java has a method: Integer.valueOf: Integer.valueOf("100") -> 100 does C# have similar? Or did you ask for something else?
3rd Oct 2019, 9:17 AM
Seb TheS
Seb TheS - avatar
0
I believe no. Char to int sure. String to int[] sure.
3rd Oct 2019, 6:54 AM
Manual
Manual - avatar