Why does the below code throw a System.FormatException -
Input string was not in a correct format
decimal sum = 0;
string valString = "3.5";
sum += Convert.ToInt32(valString);
Well, 3.5 is not a correct integer value (please, notice fraction part - .5), it's decimal in the context:
decimal sum = 0;
string valString = "3.5";
sum += Convert.ToDecimal(valString);