Five Different Variables in C#

Aidan Hart
3 min readJul 13, 2023

--

In coding there are five different variable data types, and its very important to understand how they work.

Variables have two different privacy options. The first is public, which allows every script to access that variable.

Variables have three parts. Their Private/Public reference, their data type and their name.

If I were to try and access the variable from a different script, it would be used. However, the private option only allows the script that its in to access it, meaning no other script can use it.

If one of three parts of a variable are absent, it will not work.

Now it is time to go over the five different data types of variables at your disposal.

The first variable is int. These types of variables contain integer values. Int variables are often used for storing data that need to be displayed as whole numbers. Such as the amount of hit points, how much durability is left on a weapon, etc.

If we don’t give an int variable a value, it will automatically be set as zero.

The second variable is float. Unlike int, float can hold decimal values. These can be used for more precise borders, movement, and more! Just remember to add an “f” after typing in the number of your choice. You will get a running error if you don’t.

Fun fact: All Ints are floats, but not all floats are ints.

The third variable is string. Unlike float and int, string can hold words and sentences. These can be used for messages.

Remember to use parenthesis at the beginning and end of your message, or else the program won’t run

The fourth variable is called char. Char is structured like string, but it can only hold a single letter or number

Finally, the last variable are bool. Simply put, bool or booleans is just a true or false statement. These can be used for if loops.

That wraps up this guide for different types of variables. If you like my guides, check out other guides I write about Unity and C#!

--

--