You'll want to learn about:
Both are basic task, but are incredibly important to programming.
You have a couple of approaches:
intAmount = Convert.ToInt32(txtAmount.Text);
intAmount = int.Parse(txtAmount.Text);
The easiest approach to cast
would be the above. However, the problem will occur when invalid user information may be passed. For instance a user passes example
would cause an Exception.
You'll want to sanitize the data. So you could try the following:
int amount;
if(int.TryParse(txtAmount.Text, out amount))
{
// Properly converted amount to an integer.
}
Another approach could be:
int amount = txtAmount.Text.Where(d => char.IsDigit(d));
The safest and most common would be int.TryParse
. But these are all approaches you should look into to properly handle data.
Hopefully this helps you.