Recall & Review
beginner
What is LINQ in C#?
LINQ (Language Integrated Query) is a feature in C# that allows you to query collections like arrays or lists using a readable, SQL-like syntax directly in the code.
Click to reveal answer
beginner
How do you define a custom object to use with LINQ?
A custom object is a class you create with properties. For example, a <code>Person</code> class with <code>Name</code> and <code>Age</code> properties can be used in LINQ queries.Click to reveal answer
beginner
What does this LINQ query do?<br>
var adults = people.Where(p => p.Age >= 18);
This query selects all
people whose Age is 18 or older. It filters the list to only adults.Click to reveal answer
beginner
How can you select only the names from a list of custom objects using LINQ?
Use the
Select method to pick the Name property: var names = people.Select(p => p.Name); This creates a list of names.Click to reveal answer
beginner
What is the difference between
Where and Select in LINQ?Where filters items based on a condition (like a sieve). Select transforms each item into something new (like picking a part of each item).Click to reveal answer
What does this LINQ query return?<br>
var result = people.Where(p => p.Age < 30);
✗ Incorrect
The
Where method filters the list to include only people with Age < 30.Which LINQ method would you use to get only the names from a list of Person objects?
✗ Incorrect
Select is used to transform each object into a specific property, like Name.Given a list of custom objects, how do you filter items with LINQ?
✗ Incorrect
Where filters items based on a condition.What type of object does a LINQ query like
people.Where(...) return?✗ Incorrect
LINQ
Where returns a collection of items that match the condition.Which keyword is used in LINQ lambda expressions to represent each item?
✗ Incorrect
In
p => p.Age > 18, p represents each item in the collection.Explain how to use LINQ to filter a list of custom objects based on a property.
Think about how you pick only some items from a list.
You got /5 concepts.
Describe the difference between the LINQ methods Where and Select when working with custom objects.
One chooses items, the other picks parts of items.
You got /4 concepts.