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

LINQ with custom objects in C Sharp (C#) - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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);
AAll people younger than 30
BAll people older than 30
CAll people exactly 30 years old
DAll people regardless of age
Which LINQ method would you use to get only the names from a list of Person objects?
AWhere
BGroupBy
COrderBy
DSelect
Given a list of custom objects, how do you filter items with LINQ?
AUse Where
BUse Select
CUse OrderBy
DUse ToList
What type of object does a LINQ query like people.Where(...) return?
AA single object
BA filtered collection
CAn integer count
DA boolean value
Which keyword is used in LINQ lambda expressions to represent each item?
Aitem
Bvar
Cp
D=>
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.