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

LINQ with custom objects in C Sharp (C#) - Mini Project: Build & Apply

Choose your learning style9 modes available
LINQ with custom objects
📖 Scenario: You work in a bookstore and want to organize a list of books by their price. Each book has a title and a price.
🎯 Goal: You will create a list of book objects, set a price limit, use LINQ to find books cheaper than that limit, and then print their titles.
📋 What You'll Learn
Create a Book class with Title and Price properties
Create a list of Book objects with exact titles and prices
Create a priceLimit variable to filter books
Use LINQ query with where to select books cheaper than priceLimit
Print the titles of the filtered books
💡 Why This Matters
🌍 Real World
Filtering and selecting items from a list of custom objects is common in apps like online stores, libraries, or inventory systems.
💼 Career
Understanding LINQ with custom objects helps you write clean, readable code to query data collections efficiently in many C# jobs.
Progress0 / 4 steps
1
Create the Book class and list of books
Create a Book class with Title and Price properties. Then create a list called books with these exact entries: "C# Basics" priced 30, "LINQ in Action" priced 45, "ASP.NET Core" priced 50, "Entity Framework" priced 40.
C Sharp (C#)
Need a hint?

Define a class with two properties. Then create a list and add new Book objects with the exact titles and prices.

2
Set the price limit
Inside the Main method, create an integer variable called priceLimit and set it to 45.
C Sharp (C#)
Need a hint?

Just create an integer variable named priceLimit and assign it the value 45.

3
Use LINQ to find books cheaper than priceLimit
Use a LINQ query with var cheapBooks = from book in books where book.Price < priceLimit select book; inside the Main method, after defining priceLimit.
C Sharp (C#)
Need a hint?

Use a LINQ query expression with from, where, and select to filter books cheaper than priceLimit.

4
Print the titles of the filtered books
Use a foreach loop to print the Title of each book in cheapBooks.
C Sharp (C#)
Need a hint?

Use a foreach loop to go through cheapBooks and print each book's Title with Console.WriteLine.