How would you go about converting a string contained in a TextBox to a numeric value?
Printable View
How would you go about converting a string contained in a TextBox to a numeric value?
Code:<int variable> = int.Parse(<string value>);
The above solution should be absolutly sufficient for your program. However if you have different machines and cultures involved, use the following:
You can convert a lot of datatypes with Convert. Please make sure you pass a cultureinfo, otherwise it's machine specific and values send from one machine to another might not be convertable by the destination machine if it has different country/culture options. The example uses the current culture, and might break when you involve different cultures. For culture-independent conversion use CultureInfo.InvariantCulure.Code:<int variable> = Convert.ToInt32(<string value>, CultureInfo.CurrentCulture );