Declaring a variable, consists of telling the program to reserve a piece of memory to store some data.
Declare a Variable in C#
A variable declaration in C#, follows the following format:
🤖 Pseudocode
<DATA_TYPE> <NAME> = <VALUE>;
<DATA_TYPE>: the value data type (number, text, etc.).<NAME>: a recognizable name.<VALUE>: the initial value we want to store (optional).
// An integer variable named score with the initial value of 0. int score = 0; // A string variable named username with the initial value of "Ze". string username = "Ze"; // A boolean variable named named isAlive with the initial value of true. bool isAlive = true;
ℹ️ While it seems easy, naming variables is something that requires some careful thought.
Related Concepts
- Uses: Data Type
- Uses: Variable
- Mentions: Naming Variables