Lesson contents

Fixed values

Give a fixed value a name and reuse it wherever the same amount is needed.

Simple example

Use the same factor twice.

Start3 × 2
Result6
Program.cs
using System;

const int factor = 3;
Console.WriteLine(factor * 2);
Output
6
Advertisements

Everyday examples

Each bus ticket costs 4 coins. What do three tickets cost?

Start4 × 3
Result12
Program.cs
using System;

const int fare = 4;
Console.WriteLine(fare * 3);
Output
12
Run the example
Terminal
dotnet new console --output Lesson
cp Program.cs Lesson/Program.cs
dotnet run --project Lesson
Official documentation