0
Convert string to int on c#
Which way is the best to convert an string to an int on c#? I’ve seen the “.Toint32”, the “try method with an if” and others… I wanna know which way is the most common used so that I can put on my code. // I’m a beginner :)
1 Odpowiedź
+ 2
"best" perhaps isn't what you want eventually, not even sure there was one anyways. "most common" may also depend on some factors like the coder's or their team preference.
If it was safety that you seek, you might consider the TryParse() method which does not throw an exception upon conversion problems, such as presence of non numeric characters/symbols in the source string to be converted, which may prevent a smooth conversion process.
https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/types/how-to-convert-a-string-to-a-number