Now we are starting with value types, using variables to store data and math expressions’ value. For this I developed a program to calculate average of ages.

How was it made?

  • First was added the visual components: labels, text boxes and a button
  • The text boxes’ name were changed*
  • The button name was changed*
  • The event btnCalculate_Click was created (by double-clicking the button)
  • The code below was add


*Note: I like to rename the components because it is easier to understand and identify the things in the code. It’s a good practice for others understand your code, even more when we are developing complex systems that have a lot of lines of code.

How does it work?

After the window is open, the user needs to insert values into txtAge1, txtAge2 and txtAge3, and click “Calculate Average”. When he clicks this button, an event called “btnCalculate_Click” is activated, and these things happen inside him:

  • Variables of the type int are created
  • These variables receives the value of the text boxes
  • The average is calculated
  • A MessageBox with the average is showed
  • The text boxes are cleaned


This slideshow requires JavaScript.


Click here to download the application from


Developed in Visual Studio Community 2015

Program executed in Windows 10 Education