C# Variables

In this lesson, you will learn about Variables in C#, their usage, and examples to better understand the topic.

What is a variable in C#?

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.

Declare a variable in C#

To declare a variable in C#, you must specify its data type.


Data Type variableName;


int age;
string name;

Assign a vairiable in C#

In C#, a variable can be assigned during declaration.


int age = 28;

Also, a variable can be assigned later in the Program.


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.