Monday Notes

Today, we followed the instructions from Monday Instructions and built a very simple adder program.

In the process, we explored the difference between strings (text) and integers (numbers) when it comes to addition.

For example, when the SimpleAdder was completed, when we tried to add “10” plus “1”, instead of getting “11” we got “101.” This is because when you add strings together, it concatenates them.

We then added some test code to define two hardcoded ints, add them together, and use the .ToString() method to convert the values to strings so they could be assigned to the resultBox.Text property. ¬†We were able to see that the “+” operator works on integers the way we’d expect them.

The next exercise was to change the application to use the int.TryParse() method to turn the Text properties of the TextBox’s to numbers, so they could be added together rather than simply concatenated.

The final exercise was to add a Clear button, to empty all three TextBox controls.

Leave a Reply

Your email address will not be published. Required fields are marked *