0
0
C Sharp (C#)programming~30 mins

List methods (Add, Remove, Find, Sort) in C Sharp (C#) - Mini Project: Build & Apply

Choose your learning style9 modes available
List methods (Add, Remove, Find, Sort)
📖 Scenario: You are managing a small library's book collection. You want to keep track of book titles, add new books, remove old ones, find specific books, and keep the list sorted alphabetically.
🎯 Goal: Build a simple C# program that uses a list of book titles and applies common list methods: Add, Remove, Find, and Sort.
📋 What You'll Learn
Create a list of strings called books with exact initial titles
Add a new book title to the books list
Remove a specific book title from the books list
Find a book title in the books list using Find
Sort the books list alphabetically
Print the final sorted list of books
💡 Why This Matters
🌍 Real World
Managing collections of items like books, products, or contacts often requires adding, removing, searching, and sorting data.
💼 Career
These list methods are fundamental in many programming jobs, especially when working with collections of data in applications.
Progress0 / 4 steps
1
Create the initial list of books
Create a list of strings called books with these exact titles: "The Hobbit", "1984", "Brave New World", "Fahrenheit 451".
C Sharp (C#)
Need a hint?

Use List<string> and initialize it with the four book titles inside curly braces.

2
Add a new book to the list
Add the book title "Animal Farm" to the books list using the Add method.
C Sharp (C#)
Need a hint?

Use books.Add("Animal Farm") to add the new book.

3
Remove a book from the list
Remove the book titled "1984" from the books list using the Remove method.
C Sharp (C#)
Need a hint?

Use books.Remove("1984") to remove the book.

4
Find and sort the books, then print the list
Use the Find method on books to find the book titled "Animal Farm" and store it in a variable called foundBook. Then sort the books list alphabetically using Sort. Finally, print each book title on its own line using a foreach loop.
C Sharp (C#)
Need a hint?

Use string foundBook = books.Find(book => book == "Animal Farm") to find the book. Then call books.Sort(). Use a foreach loop to print each book.