Using Multi-parameter Indexers in C#
📖 Scenario: Imagine you manage a small hotel with rooms on different floors. You want to keep track of which guest is staying in each room using a simple system.
🎯 Goal: You will create a class with a multi-parameter indexer that lets you get and set guest names by specifying the floor and room number.
📋 What You'll Learn
Create a class called
Hotel that stores guest names.Use a multi-parameter indexer with two
int parameters: floor and room.The indexer should allow getting and setting guest names by floor and room.
Demonstrate setting and getting guest names using the indexer.
💡 Why This Matters
🌍 Real World
Multi-parameter indexers are useful when you want to access data stored in a grid or table-like structure, such as seats in a theater, cells in a spreadsheet, or rooms in a hotel.
💼 Career
Understanding multi-parameter indexers helps you write cleaner and more intuitive code when working with complex data structures, a common task in software development jobs.
Progress0 / 4 steps