Variables. The Building Blocks of Programming.

Caleb Breuner
3 min readMay 30, 2021

What are variables in C#?

Image Reference: junilearning.com

Variables are locations within a program that store data. This data can take on the form of several different types. In programming, it is important to recognize these types and how to incorporate them into one’s code.

Below is a list of the different variable types. [Note: The following information can be referenced from codemahal.com and Claudio Grassi on Medium.]

int — Integer is assigned when a variable includes a whole number without a decimal.

float — Float is for values with decimals. The value assigned to the variable is followed by the letter f.

double — This is similar to floats, but can store values with more decimal places.

bool — Boolean is for variables that store a simple True or False value.

char — Character stores a single letter, number, space or other special character.

string — Strings hold a series of letters, numbers, and words and often contain whole phrases. They are written inside double quotes.

Often times when variables are written and assigned a data type in a code, an access modifier is placed before the data type. There are two types of access modifiers to consider: public and private. The below image shows how these access modifiers are written with their variables.

When public is the access modifier, it allows the variable to be referenced by other classes/scripts outside of the original. Public allows one to adjust a variable’s value within the Unity editor. [Claudio Grassi on Medium]

With private, the value can only be accessed within its own class. Other classes/scripts cannot access or reference the value. It is common practice to include an underscore in front of a private variable. [Claudio Grassi on Medium]

--

--