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

LINQ method syntax in C Sharp (C#) - Mini Project: Build & Apply

Choose your learning style9 modes available
Filter and Select with LINQ Method Syntax
📖 Scenario: You work in a bookstore and have a list of books with their prices. You want to find all books that cost less than $20 and get their titles.
🎯 Goal: Build a C# program that uses LINQ method syntax to filter books priced below $20 and select their titles.
📋 What You'll Learn
Create a list of books with exact titles and prices
Create a price limit variable
Use LINQ method syntax with Where and Select to filter and select book titles
Print the filtered book titles
💡 Why This Matters
🌍 Real World
Filtering and selecting data from collections is common in apps like online stores, libraries, and inventory systems.
💼 Career
Knowing LINQ method syntax helps you write clear and efficient queries in C# for data processing tasks.
Progress0 / 4 steps
1
Create the list of books
Create a list of tuples called books with these exact entries: ("C# Basics", 15.99), ("LINQ in Action", 25.50), ("ASP.NET Core", 18.75), ("Entity Framework", 22.30), ("Clean Code", 19.99).
C Sharp (C#)
Need a hint?

Use new List<(string Title, double Price)> { ... } to create the list.

2
Set the price limit
Create a double variable called priceLimit and set it to 20.0.
C Sharp (C#)
Need a hint?

Use double priceLimit = 20.0; to set the limit.

3
Filter and select book titles using LINQ method syntax
Create a variable called affordableBooks that uses LINQ method syntax on books to filter books where Price < priceLimit using Where, then select only the Title using Select.
C Sharp (C#)
Need a hint?

Chain Where and Select methods with lambda expressions.

4
Print the filtered book titles
Use a foreach loop to print each title in affordableBooks on its own line.
C Sharp (C#)
Need a hint?

Use foreach (var title in affordableBooks) { Console.WriteLine(title); } to print.