Lesson contents

Modeling data

Keep the quantity and unit price together in one record. Give the two fields names so you can tell what each number means.

Simple example

Multiply two fields.

Start2 × 3
Result6
Program.cs
using System;

var item = (units: 2, price: 3);
Console.WriteLine(item.units * item.price);
Output
6
Advertisements

Everyday examples

A receipt lists four notebooks at three coins each. What is the cost of this line on the receipt?

Start4 notebooks × 3
Result12
Program.cs
using System;

var item = (units: 4, price: 3);
Console.WriteLine(item.units * item.price);
Output
12
Run the example
Terminal
dotnet new console --output Lesson
cp Program.cs Lesson/Program.cs
dotnet run --project Lesson
Official documentation