Variables
A variable is a “temporary holding place” for a value. Think of it as a box that can store a single item. The value inside a variable can be of different types, for example:
- An integer (an
int) - a word or sentence (a
string) - Sooooo many other things that we'll visit later...
Defining Variables
Variables in C# are composed of a type, name, and a value:
type variableName = value;
Some Examples are:
// ints are integer numbers
int coolNum = 42;
// strings are words or sentences (a string of characters)
string cat = "Meowzer";
Console.WriteLine(cat);
In programming, the = sign does not work like it works in your math classes:
- The first line creates a variable
catand assigns"Meowzer"as its value - The second line prints the value of
catto theConsole

Another way to think about this is in terms of boxes:
variableNameis like the box's label (it must always be unique)=sign is like putting something in a boxConsole.WriteLine()is like checking out whats in the box
Variable Names
❌ Variable names CANNOT:
- Start with a number
- Contain a space
" ", hashtag#, exclamation points!, or periods. - Be a reserved word (e.g.
Console)
✅ Variables CAN:
- Contain letters and numbers after the first character
- Be written in
camelCasefor multi-word identifiers - Be descriptive & meaningful of what they contain
Multi-word Variable Names
- Naming standards vary with programming language. For now, just stick to
camelCase
Resources
Bultena, Sandra and Youmna Badawy. "Variables and Constants." 420-SN1 Notes, John Abbott College, john-abbott-college.github.io/SN1-Notes/topics/04_variables/02_variables/02_variables.html
"Naming Convention Camel Case, Kebab Case & Snake Case." Junior to Expert, 2 Sept. 2022, juniortoexpert.com/en/naming-convention