From the course: C# Algorithms
Unlock the full course today
Join today to access over 24,900 courses taught by industry experts.
Dictionary and HashSet operations in C# - C# Tutorial
From the course: C# Algorithms
Dictionary and HashSet operations in C#
- [Instructor] Let's look at how to use hash structures so we can build algorithms that work with key-value pairs. We start off with an employee class. Each employee has a name, ID and department, but eventually, this class could include quite a bit of data. In the main function, we create three employees, giving them values for each piece of data. In order to access each employee efficiently, we can choose a unique key out of these three attributes as an identifier for each employee. Then, we can use the key to quickly retrieve a given employees data. Two employees might have the same name and they might have the same department, but no two employees should have the same ID, so we'll use that as our key. The value in the key-value pair will be the associated employee data. Let's use the dictionary type to store our employees by ID. The ID is an integer. So int employee. We'll call it employeesById and create a new dictionary. Now to add an employee to the dictionary, we can use the…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.