Solution 1 may fail on possible cultural differences.
Try:
int price = int.Parse(priceTextBox.Text, CultureInfo.CurrentCulture);
You get the numeric value from this.
Throws a
FormatException
if the
.Text
is not an integer value.
Use whatever is appropriate instead of
CultureInfo.CurrentCulture
for different cultures,
e.g.
CultureInfo.InvariantCulture
If you'd rather some different error handling for the parse failures:
int price;
if (!int.TryParse(priceTextBox.Text, NumberStyles.Integer, CultureInfo.CurrentCulture, out price))
{
}