C# Variables for Absolute Beginners

We obviously won’t store water in a basket.

We need a drum.

It would also be unwise to store shoes in a drum (even though we can) we should use a wardrobe or a shoe rack.

In the same way, in programming, different types of values are stored in different types of containers.

The types of values in a computer program will not be water and shoes though.

Computer programs store the following types of values:Text: an example of text includes your social media status updates.

All the words you type are saved as text in the computer software.

They are stored in a type of variable(container) called the STRINGNumbers: When you enter your age in a computer (say 15 years old) it is stored as a number.

Numbers in computer memory are stored in a type of variable (container) called INT.

Decimals: Sometimes you are making a banking application and every last kobo matters.

You don’t want to tell a customer they have 2 Naira when they actually have 2 Naira 50 kobo.



for situations where you need to save decimal numbers, you use the DOUBLE type.

We have heard enough grammar, let us now use some of these variables, or containers so you will get a better understanding.

Before we begin, I will give you a magic line of code.

It helps you to display information to your users.

This line of code is Console.

WriteLine();Ignore that for now.

And let us proceed.

We will create a few variables now and save something inside of them.

Tip: Create a new console application and follow this example.

First, let us create a variable to save my name.

We need to create the container and put my name inside.

We do that using the line of codestring personsName = “Vincent Nwonah”;Let us create another variable and save my age inside.

int personsAge = 900;Variable DeclarationsLet us take a look at these two examples.

The first word on each line tells the system what type of variable we want to create, it is a way of telling the computer what type of information we will store in the variable.

In the first example, we are telling the system that we are creating a variable that will save text — A person’s name, and the second example we are saying we will save a number — a person’s age.

The next word on the first line is myName.

This is the name of the variable.

The name of the variable is necessary so you can use it later in the program.

Imagine you have stored water in different buckets, and you need to tell someone to bring a specific one to you, you may say; I need the water in the GREEN BUCKET, you are in essence naming that bucket because you need a way to refer to it.

In the same way, variable names are necessary so we can refer to variables later.

Next in line is the equality sign and my name.

On that line, we are saying: take this piece of information and save it inside this container I have created.

Finally, let us display the values we have saved in out variables.

we do this using that special code: Console.

WriteLine(); So, to see what’s in our variables, we say Console.

WriteLine(variableName); To see what is in personsName therefore, we have Console.

WriteLine(personsName);Your final code window should look like this.

Ignore the “Console.

ReadLine();” for now.

Run the code and see your values displayed!If you have any questions shoot me a mail at vnwonah (at) outlook.



. More details

Leave a Reply