Recall & Review
beginner
What is the purpose of the
Select clause in LINQ?The
Select clause is used to choose or transform elements from a collection into a new form or shape.Click to reveal answer
beginner
How do you project only the names from a list of
Person objects using LINQ?You use
Select(person => person.Name) to create a new collection of just the names.Click to reveal answer
intermediate
What does this LINQ query do?<br>
var result = people.Select(p => new { p.Name, p.Age });It creates a new collection of anonymous objects, each containing only the
Name and Age properties from each Person.Click to reveal answer
intermediate
Can the
Select clause be used to change the type of elements in the collection?Yes,
Select can transform elements into any type, including anonymous types, new classes, or simple values.Click to reveal answer
beginner
What happens if you use
Select without changing the element inside the lambda?The query returns the original elements unchanged, effectively creating a copy of the collection.
Click to reveal answer
What does the
Select clause do in a LINQ query?✗ Incorrect
The
Select clause projects each element into a new form or shape.Which syntax correctly projects only the
Age property from a list of Person objects named people?✗ Incorrect
Select is used to project or transform elements, so people.Select(p => p.Age) returns only ages.What type of object is created by this query?<br>
people.Select(p => new { p.Name, p.City })✗ Incorrect
The query creates anonymous objects containing only the
Name and City properties.If you want to keep the original elements unchanged, what should your
Select clause look like?✗ Incorrect
Using
Select(p => p) returns the original elements without changes.Can
Select be used to create a list of a different type than the original collection?✗ Incorrect
Select can transform elements into any type, including anonymous types or new classes.Explain how the
Select clause is used to transform data in a LINQ query.Think about how you pick or change data from a list.
You got /4 concepts.
Describe the difference between using
Select to return original elements and using it to create new anonymous types.Consider when you want the same data or a new form of data.
You got /4 concepts.