A bunch of random numbers, gibberish that doesn’t make sense but can produce life-changing applications in desktop, mobile and webspace.
This is usually the flow in conversations I have with my non-developer friends when discussing computer programming. For non-developers, this world can be quite intimidating and understandably so I will use a simple Console App program, that calculates the end user’s age.
Let’s first identify all the tools we need to assemble a Console App program. So, all we need to install is Microsoft Visual Studio on our Windows system that meets the minimum requirements. Once installed, we can launch Microsoft Visual Studio and then create a Console Application project, selecting C# as our preferred programming language.
After which we will be presented with a similar code snippet, as below:
.Net Class Library – The “using” statement is used to import the .Net Framework modules that are required to run code on a Windows system.
Open & Close – We use containers a lot to segment code and these segments are scoped by open “{” and “}” close curly braces.
Namespace – This is a container that encapsulates classes.
Class – All code needs to be logically defined in a module called a “class”.
Method Name – This is the code block that contains all the statements and in a Console App program, this is the code block that gets executed first.
Comment – This is the non-executed text that is used to explain the source code.
Console.Write/WriteLine – “Console.Write” renders text inline and “Console.WriteLine” renders text on a new line.
Console.ReadLine – Gets user input.
int yourBirthYear – We declare a variable called “yourBirthYear” that stores an integer(numeric) value.
Convert.ToInt32 – A method used to convert text to an integer.
int yourAge = todaysYear – yourBirthYear – Finally we calculate your age, we take today’s year derived from the Windows system and then subtract the year captured by the end-user. The result gets stored in an integer variable called “yourAge”, which gets printed on the next line.
We can now press F5 to execute the above Console App program. Pending there are no errors in our source code, the below snippet will pop up. Prompting the end-user to enter the year there were born.
At this stage, we have successfully built our first computer program.
To view more Articles, please visit our Leads 2 Business Blog.
If you are interested in becoming one of our subscribers, please visit Leads 2 Business.
To view notes with screenshots on how to use our website, please visit Leads 2 Business Wiki.
About Andile Shange
I'm a Software Developer at Leads 2 Business since 02 June 2014.