Relational patterns
📖 Scenario: You are building a simple program to check the age of a person and categorize them as a child, teenager, adult, or senior.
🎯 Goal: Create a program that uses relational patterns in a switch expression to print the correct age category based on the person's age.
📋 What You'll Learn
Create an integer variable
age with the exact value 25.Create a string variable
category to hold the age group.Use a
switch expression with relational patterns to assign the correct category:< 13 is "Child"< 20 is "Teenager"< 65 is "Adult"Anything else is "Senior"
Print the
category variable.💡 Why This Matters
🌍 Real World
Age categories are used in many apps like games, websites, and services to customize content or permissions.
💼 Career
Understanding relational patterns helps you write clear and concise code for decision making in professional C# development.
Progress0 / 4 steps