Tell me, I have a TextBox, in it I want to enter a password and transfer values to a variable of type int ... did I make the code correctly?
int pass; int.TryParse(textPassword.Text, out pass);
* textPassword = This is a TextBox
Tell me, I have a TextBox, in it I want to enter a password and transfer values to a variable of type int ... did I make the code correctly?
int pass; int.TryParse(textPassword.Text, out pass);
* textPassword = This is a TextBox
Source: https://ru.stackoverflow.com/questions/67955/
All Articles
Convert.ToInt32()
- SpecterConvert
class, you still need to handle exceptions. Both have the right to life, but IMHO is better to use tools that help avoid exceptions. In this case, if you just need to convert the value without figuring out the reasons why the conversion may fall - it is better to use TryParse, if you want the method to throw an exception and handle some situation (specific to the type of exception) - then use the methods of the classConvert
- Eugene Cheverda