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
using System;
var item = (units: 2, price: 3);
Console.WriteLine(item.units * item.price);
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
using System;
var item = (units: 4, price: 3);
Console.WriteLine(item.units * item.price);
12
Run the example
dotnet new console --output Lesson
cp Program.cs Lesson/Program.cs
dotnet run --project Lesson