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

LINQ with custom objects in C Sharp (C#) - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to select all names from the list of people.

C Sharp (C#)
var names = people.Select(person => person.[1]);
Drag options to blanks, or click blank then click option'
AGetHashCode()
BAge
CToString()
DName
Attempts:
3 left
💡 Hint
Common Mistakes
Selecting Age instead of Name.
Using methods like ToString() which return a string but are not properties.
2fill in blank
medium

Complete the code to filter people older than 30.

C Sharp (C#)
var olderThan30 = people.Where(person => person.[1] > 30);
Drag options to blanks, or click blank then click option'
AName
BToString()
CAge
DLength
Attempts:
3 left
💡 Hint
Common Mistakes
Using Name property instead of Age.
Trying to use Length which is not a property of Person.
3fill in blank
hard

Fix the error in the LINQ query to order people by their age.

C Sharp (C#)
var ordered = people.OrderBy(person => person.[1]);
Drag options to blanks, or click blank then click option'
AAge
BCount
CName
DLength
Attempts:
3 left
💡 Hint
Common Mistakes
Using Name to order when age is required.
Using Count or Length which are not properties of Person.
4fill in blank
hard

Fill both blanks to create a dictionary with names as keys and ages as values for people older than 25.

C Sharp (C#)
var dict = people.Where(p => p.[1] > 25).ToDictionary(p => p.[2], p => p.Age);
Drag options to blanks, or click blank then click option'
AAge
BName
CToString()
DLength
Attempts:
3 left
💡 Hint
Common Mistakes
Using Name instead of Age in the filter.
Using ToString() or Length which are not suitable here.
5fill in blank
hard

Fill all three blanks to select uppercase names of people younger than 40.

C Sharp (C#)
var result = people.Where(p => p.[1] < 40).Select(p => p.[2].[3]());
Drag options to blanks, or click blank then click option'
AAge
BName
CToUpper
DToLower
Attempts:
3 left
💡 Hint
Common Mistakes
Using ToLower instead of ToUpper.
Using Name in the filter instead of Age.