Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Змінні | Початок Роботи
Quizzes & Challenges
Quizzes
Challenges
/
Основи C#

bookЗмінні

In programming, variables are like labeled containers that hold some value. The data may be in the form of a number, text, boolean (true / false) or some other type.

The term "variable" means "changeable" hence the value that a variable holds can be changed any time.

We can create a simple variable in C# using the var keyword:

var variableName = value;

The different components of this syntax are highlighted in the graphic below:

The equal sign (=) is called the assignment operator. It is used for assigning values to variables.

We will only use numbers for values of variables in this section. In the next section, we will learn how to work with different types of data in appropriate detail.

Note

A statement which includes = operator is called an assignment statement, for-example: variableName = value.

main.cs

main.cs

copy
1234567891011
namespace TestConsoleApp { internal class Program { static void Main(string[] args) { var myVar = 10; System.Console.WriteLine(myVar); // Outputs: 10 } } }

This above code creates a new variable called myVar which holds the value 10. It then outputs the value of the variable using the System.Console.WriteLine statement.

We can change the value it holds using the assignment operator:

main.cs

main.cs

copy
1234567891011121314
namespace TestConsoleApp { internal class Program { static void Main(string[] args) { var myVar = 10; System.Console.WriteLine(myVar); // Outputs: 10 myVar = 20; System.Console.WriteLine(myVar); // Outputs: 20 } } }

Note

The var keyword is only used when creating a new variable. Therefore when we are assigning a new value to an already declared variable we only use the assignment operator (=), as is the case in the myVar = 20 statement.

question mark

Which keyword is used for creating a new variable?

Select the correct answer

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 7

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

Suggested prompts:

Can you explain more about the different data types in C#?

What are some common mistakes to avoid when naming variables?

How do I display variable values in the console?

bookЗмінні

Свайпніть щоб показати меню

In programming, variables are like labeled containers that hold some value. The data may be in the form of a number, text, boolean (true / false) or some other type.

The term "variable" means "changeable" hence the value that a variable holds can be changed any time.

We can create a simple variable in C# using the var keyword:

var variableName = value;

The different components of this syntax are highlighted in the graphic below:

The equal sign (=) is called the assignment operator. It is used for assigning values to variables.

We will only use numbers for values of variables in this section. In the next section, we will learn how to work with different types of data in appropriate detail.

Note

A statement which includes = operator is called an assignment statement, for-example: variableName = value.

main.cs

main.cs

copy
1234567891011
namespace TestConsoleApp { internal class Program { static void Main(string[] args) { var myVar = 10; System.Console.WriteLine(myVar); // Outputs: 10 } } }

This above code creates a new variable called myVar which holds the value 10. It then outputs the value of the variable using the System.Console.WriteLine statement.

We can change the value it holds using the assignment operator:

main.cs

main.cs

copy
1234567891011121314
namespace TestConsoleApp { internal class Program { static void Main(string[] args) { var myVar = 10; System.Console.WriteLine(myVar); // Outputs: 10 myVar = 20; System.Console.WriteLine(myVar); // Outputs: 20 } } }

Note

The var keyword is only used when creating a new variable. Therefore when we are assigning a new value to an already declared variable we only use the assignment operator (=), as is the case in the myVar = 20 statement.

question mark

Which keyword is used for creating a new variable?

Select the correct answer

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 7
some-alt