Lesson contents

Input validation

Check that the requested seat is between one and the last seat. Returning false lets the booking screen ask for a new number.

Simple example

Is zero in the range one to three?

Start0 · 1–3
ResultFalse
Program.cs
using System;

Console.WriteLine(0 >= 1 && 0 <= 3);
Output
False
Advertisements

Everyday examples

A school bus has 30 seats. Can a learner reserve seat 30?

StartSeat 30 · 30 seats
ResultTrue
Program.cs
using System;

Console.WriteLine(30 >= 1 && 30 <= 30);
Output
True
Run the example
Terminal
dotnet new console --output Lesson
cp Program.cs Lesson/Program.cs
dotnet run --project Lesson
Official documentation