Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Selecting Age instead of Name.
Using methods like ToString() which return a string but are not properties.
✗ Incorrect
The Name property holds the person's name, which we want to select.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Name property instead of Age.
Trying to use Length which is not a property of Person.
✗ Incorrect
The Age property holds the person's age, which we compare to 30.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Name to order when age is required.
Using Count or Length which are not properties of Person.
✗ Incorrect
Ordering by Age sorts people by their age correctly.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Name instead of Age in the filter.
Using ToString() or Length which are not suitable here.
✗ Incorrect
Filter by Age > 25, then use Name as dictionary keys.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using ToLower instead of ToUpper.
Using Name in the filter instead of Age.
✗ Incorrect
Filter by Age less than 40, select Name, then convert to uppercase with ToUpper().