C# Error (Cannot Implicitly convert type ‘string’ to ‘int’)

The TxtAmountA.Text is a string. You are attempting to set the variable intAmountA which is an integer to a string value, thus the error. You need to parse the integer out of the string in the textbox.

intAmountA = int.Parse(TxtAmountA.Text);

However, be aware that if what is in TxtAmountA.Text is not something that can be cast to an integer, you will get an exception. That is when you can use the conditional int.TryParse(string value, out integer);

Leave a Comment