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

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

Choose your learning style9 modes available
LINQ Query Syntax
📖 Scenario: You work in a bookstore. You have a list of books with their titles and prices. You want to find all books that cost less than $20 to recommend to budget readers.
🎯 Goal: Build a C# program that uses LINQ query syntax to select books priced below $20 from a list and display their titles.
📋 What You'll Learn
Create a list of books with exact titles and prices
Create a price limit variable set to 20
Use LINQ query syntax with from, where, and select to find books cheaper than the price limit
Print the titles of the selected books
💡 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 query syntax helps you write clear and efficient data queries in C# jobs involving data processing and software development.
Progress0 / 4 steps
1
Create the list of books
Create a list of books called books with these exact entries: ("C# Basics", 15), ("Advanced C#", 25), ("LINQ in Action", 18), ("ASP.NET Core", 30), ("Entity Framework", 12). Use a list of tuples with string and int types.
C Sharp (C#)
Need a hint?

Use List<(string, int)> and add the tuples exactly as shown.

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

Use int priceLimit = 20; inside the Main method.

3
Write the LINQ query
Use LINQ query syntax to create a variable called cheapBooks that selects the Title of books from books where the Price is less than priceLimit. Use from, where, and select keywords.
C Sharp (C#)
Need a hint?

Use var cheapBooks = from book in books where book.Price < priceLimit select book.Title;

4
Print the selected book titles
Use a foreach loop with variable title to iterate over cheapBooks and print each title on its own line using Console.WriteLine.
C Sharp (C#)
Need a hint?

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