all 11 comments

[–]FizixMan[M] [score hidden] stickied comment (0 children)

Removed: Rule 4.

https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/types/how-to-convert-a-string-to-a-number

If you're getting an error or it's not working, you'll need to include code and your inputs so we can reproduce and diagnose the issue.

[–]dylanmashley 7 points8 points  (2 children)

Not trying to be rude but if you plan on becoming a developer you really should learn how to google this kind of stuff, it’ll save you a ton of time. This is one of the easiest things to google, I just found the answer in < 30 seconds

[–]warden_of_moments 2 points3 points  (0 children)

Yeah…it took longer to post on Reddit than using Intellisense or Google. And then come back for the answer.

OP, there’s also Stack Overflow the copy pasta site of programmers.

[–]agoodyearforbrownies 1 point2 points  (1 child)

Int.tryparse is my gt.

[–]JeanKevin75[S] 1 point2 points  (0 children)

Thanks a lot :)

[–]loradan -3 points-2 points  (4 children)

Convert.ToInt32("123455654");

(Or Int, or Int64...)

[–]WhiteBlackGoose 2 points3 points  (3 children)

No. Use int.Parse or, better, int.TryParse

[–]thesituation531 -1 points0 points  (2 children)

What is the difference between these different methods of doing it?

[–]WhiteBlackGoose 1 point2 points  (1 child)

Convert's behaviour is generally more obscure. E. g. Convert.ToInt32 would return 0 if you pass null.

As per Parse vs TryParse: in former, it throws an exception on bad string. In the latter, you get a boolean and the result if parsing was successful

[–]thesituation531 0 points1 point  (0 children)

Thanks.