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

Select clause projection in C Sharp (C#) - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
ATransforms each element into a new form
BFilters elements based on a condition
CSorts elements in ascending order
DJoins two collections
Which syntax correctly projects only the Age property from a list of Person objects named people?
Apeople.GroupBy(p =&gt; p.Age)
Bpeople.Where(p =&gt; p.Age)
Cpeople.OrderBy(p =&gt; p.Age)
Dpeople.Select(p =&gt; p.Age)
What type of object is created by this query?<br>
people.Select(p => new { p.Name, p.City })
AAnonymous type with Name and City
BList of strings
COriginal Person objects
DInteger values
If you want to keep the original elements unchanged, what should your Select clause look like?
ASelect(p =&gt; new { p.Name })
BSelect(p =&gt; p.Name)
CSelect(p =&gt; p)
DSelect(p =&gt; p.Age)
Can Select be used to create a list of a different type than the original collection?
ANo, it must keep the same type
BYes, it can transform elements into any type
COnly if the types are numeric
DOnly if the types are strings
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.