In this lesson, you will learn about Variables in C#, their usage, and examples to better understand the topic.
In C# and programming in general, a variable is a memory location represented by a name. Its purpose is to store data to use later in the Program. Every variable in C# needs a data type, such as string, integer, boolean, etc. we will discuss data types in detail in the next lesson.
To declare a variable in C#, you must specify its data type.
Syntax
Data Type variableName;
Example
int age; string name;
In C#, a variable can be assigned during declaration.
Example
int age = 28;
Also, a variable can be assigned later in the Program.
Example
int age; age = 28;
This concludes the C# Variables lesson. In the next lesson, you will learn different data types in C# and their usage.