Practice Projects - Apply Your Collections Knowledge in Real C# Scenarios
Vaibhav • September 10, 2025
The best way to master arrays and collections is to use them in real projects. This article gives you a set of
practical, beginner-friendly mini-projects that reinforce everything you’ve learned in Chapter 7. Each project
includes a clear goal, suggested steps, and sample code snippets to help you get started. You’ll use List<string>
, Dictionary<string,int>
, HashSet<string>
, arrays, and more-just like in professional C# code.
These projects are designed to be completed with only the concepts covered so far: initialization, iteration, adding/removing, searching, and best practices. No advanced features or external libraries required!
Project 1: Unique Word Counter
Goal: Read a sentence from the user, split it into words, and count how many unique words appear.
- Use
HashSet<string>
for uniqueness. - Use
Split
andTrim
for basic text processing.
Console.WriteLine("Enter a sentence:");
string input = Console.ReadLine();
string[] words = input.Split(' ', StringSplitOptions.RemoveEmptyEntries);
var uniqueWords = new HashSet<string>();
foreach (string w in words)
uniqueWords.Add(w.Trim().ToLower());
Console.WriteLine("Unique word count: " + uniqueWords.Count);
Project 2: Simple Contact Book
Goal: Store names and phone numbers, allow adding, searching, and listing all contacts.
- Use
Dictionary<string,string>
for fast lookups. - Use
TryGetValue
for safe searching.
var contacts = new Dictionary<string, string>();
contacts["Alice"] = "555-1234";
contacts["Bob"] = "555-5678";
// Search
Console.WriteLine("Enter name to search:");
string name = Console.ReadLine();
if (contacts.TryGetValue(name, out string phone))
Console.WriteLine(name + ": " + phone);
else
Console.WriteLine("Contact not found.");
// List all
foreach (var kv in contacts)
Console.WriteLine(kv.Key + ": " + kv.Value);
Project 3: Top Scores Tracker
Goal: Store a list of scores, sort them, and display the top 3.
- Use
List<int>
andSort
. - Use
Count
and index-based access.
var scores = new List<int> { 90, 85, 100, 78, 88 };
scores.Sort();
scores.Reverse(); // highest first
for (int i = 0; i < Math.Min(3, scores.Count); i++)
Console.WriteLine("Top " + (i+1) + ": " + scores[i]);
Project 4: Grocery List Manager
Goal: Add items to a grocery list, remove items, and print the final list.
- Use
List<string>
for dynamic management. - Use
Add
,Remove
, andforeach
.
var groceries = new List<string>();
groceries.Add("Milk");
groceries.Add("Eggs");
groceries.Add("Bread");
groceries.Remove("Eggs");
foreach (string item in groceries)
Console.WriteLine(item);
Project 5: Attendance Tracker
Goal: Track which students attended a class, and print only those who were present.
- Use
HashSet<string>
for attendance. - Use
Contains
for membership checks.
var allStudents = new List<string> { "Alice", "Bob", "Charlie", "Dana" };
var present = new HashSet<string> { "Alice", "Dana" };
foreach (string student in allStudents)
if (present.Contains(student))
Console.WriteLine(student + " was present.");
Tips for Success
- Start with a small, clear goal and build up.
- Use initializers for sample data, and
foreach
for easy iteration. - Test edge cases: empty lists, missing keys, duplicate entries.
- Refactor your code to use best practices from previous articles.
Try combining multiple collections (e.g., a List<string>
and a HashSet<string>
) for more advanced logic. Experiment, break things, and
learn by doing!
Summary
These practice projects help you apply everything you’ve learned about arrays and collections in C#. By building simple tools like word counters, contact books, and score trackers, you’ll gain confidence and fluency with the most important data structures in real-world programming. Keep experimenting, and revisit these projects as you learn new features in future chapters!