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

LINQ performance considerations 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 use LINQ to filter numbers greater than 10.

C Sharp (C#)
var result = numbers.Where(n => n [1] 10);
Drag options to blanks, or click blank then click option'
A==
B<
C>
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' will select numbers less than 10, which is incorrect.
Using '==' selects only numbers equal to 10, not greater.
2fill in blank
medium

Complete the code to convert the filtered result to a list for better performance.

C Sharp (C#)
var list = result.[1]();
Drag options to blanks, or click blank then click option'
AWhere
BToArray
CSelect
DToList
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Where' again does not materialize the query.
Using 'Select' is for projection, not materialization.
3fill in blank
hard

Fix the error in the LINQ query to avoid multiple enumerations causing performance issues.

C Sharp (C#)
var count = [1].Count();
var first = numbers.First();
Drag options to blanks, or click blank then click option'
Anumbers
Bnumbers.Select(n => n * 2)
Cnumbers.Where(n => n > 5)
Dnumbers.OrderBy(n => n)
Attempts:
3 left
💡 Hint
Common Mistakes
Using a query expression directly causes it to run multiple times.
Not materializing the query can cause performance hits.
4fill in blank
hard

Fill both blanks to create a dictionary from a list with keys as IDs and values as names.

C Sharp (C#)
var dict = people.ToDictionary(p => p[1], p => p[2]);
Drag options to blanks, or click blank then click option'
A.Id
B.Name
C.Age
D.Address
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-unique fields as keys causes runtime errors.
Swapping key and value selectors leads to incorrect dictionary.
5fill in blank
hard

Fill all three blanks to create a filtered and projected list of uppercase names for people older than 30.

C Sharp (C#)
var result = people.Where(p => p[1] > 30).Select(p => p[2].[3]()).ToList();
Drag options to blanks, or click blank then click option'
A.Age
B.Name
CToUpper
DToLower
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'ToLower' instead of 'ToUpper' changes the case incorrectly.
Filtering by wrong property leads to wrong results.