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

Select clause projection in C Sharp (C#) - Mini Project: Build & Apply

Choose your learning style9 modes available
Select Clause Projection in C#
📖 Scenario: You work in a bookstore and have a list of books with their details. You want to create a simple list showing only the book titles and their prices.
🎯 Goal: Build a C# program that uses LINQ's select clause to create a new list containing only the titles and prices of books.
📋 What You'll Learn
Create a list of books with title, author, and price
Create a variable to hold the minimum price filter
Use a LINQ query with select clause to project only title and price
Print the projected list showing title and price
💡 Why This Matters
🌍 Real World
Selecting and projecting data is common when working with collections, such as filtering products in a store or showing user details in an app.
💼 Career
Understanding LINQ and data projection is important for C# developers working on data processing, reporting, or UI display tasks.
Progress0 / 4 steps
1
Create the list of books
Create a list called books of type List<Book> with these exact entries: new Book("The Hobbit", "J.R.R. Tolkien", 15.99m), new Book("1984", "George Orwell", 12.50m), new Book("Clean Code", "Robert C. Martin", 33.99m). Also define the Book class with public properties Title, Author, and Price.
C Sharp (C#)
Need a hint?

Define a class Book with properties for title, author, and price. Then create a List<Book> with the given books.

2
Add a minimum price filter
Create a decimal variable called minPrice and set it to 13.00m.
C Sharp (C#)
Need a hint?

Just create a decimal variable named minPrice and assign it the value 13.00m.

3
Use LINQ select clause to project title and price
Write a LINQ query called selectedBooks that selects from books only those with Price greater than or equal to minPrice. Use the select clause to create an anonymous type with properties Title and Price.
C Sharp (C#)
Need a hint?

Use a LINQ query with from, where, and select clauses. The select clause should create an anonymous type with Title and Price.

4
Print the selected book titles and prices
Use a foreach loop to print each book's Title and Price from selectedBooks. Format the output as: Title: [Title], Price: [Price].
C Sharp (C#)
Need a hint?

Use a foreach loop to go through selectedBooks and print each book's title and price using Console.WriteLine with string interpolation.