Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Declaring Constants | Dealing with Data Types
course content

Зміст курсу

C# Basics

Declaring ConstantsDeclaring Constants

Constants are similar to variables however their value is always set at the declaration time and cannot be changed later.

They are useful in making the code easier to understand by indicating which values do not and are not supposed to be changed throughout the program. Moreover, it minimizes accidental unwanted changes to the data hence reducing bugs in the code.

When declaring a constant we use a similar syntax to variable declaration but we add the keyword const before it:

cs

main.cs

If we try to modify a constant, the compiler will show an error:

cs

main.cs

question-icon

Complete the code for declaring a constant called `pi` having a value of `3.14`:

Натисніть або перетягніть елементи та заповніть пропуски

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

Секція 2. Розділ 10
course content

Зміст курсу

C# Basics

Declaring ConstantsDeclaring Constants

Constants are similar to variables however their value is always set at the declaration time and cannot be changed later.

They are useful in making the code easier to understand by indicating which values do not and are not supposed to be changed throughout the program. Moreover, it minimizes accidental unwanted changes to the data hence reducing bugs in the code.

When declaring a constant we use a similar syntax to variable declaration but we add the keyword const before it:

cs

main.cs

If we try to modify a constant, the compiler will show an error:

cs

main.cs

question-icon

Complete the code for declaring a constant called `pi` having a value of `3.14`:

Натисніть або перетягніть елементи та заповніть пропуски

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

Секція 2. Розділ 10
some-alt