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

OrderBy and sorting 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 sort the list of numbers in ascending order using LINQ.

C Sharp (C#)
var sortedNumbers = numbers.[1](n => n);
Drag options to blanks, or click blank then click option'
AOrderBy
BWhere
CSelect
DGroupBy
Attempts:
3 left
💡 Hint
Common Mistakes
Using Where instead of OrderBy will filter elements, not sort them.
Select projects elements but does not sort.
GroupBy groups elements but does not sort.
2fill in blank
medium

Complete the code to sort the list of strings by their length in descending order.

C Sharp (C#)
var sortedStrings = strings.OrderByDescending(s => s.[1]);
Drag options to blanks, or click blank then click option'
ACount
BCapacity
CSize
DLength
Attempts:
3 left
💡 Hint
Common Mistakes
Using Count is for collections, not strings.
Size and Capacity are not valid string properties.
3fill in blank
hard

Fix the error in the code to sort a list of objects by their Age property in ascending order.

C Sharp (C#)
var sortedPeople = people.[1](p => p.Age);
Drag options to blanks, or click blank then click option'
AOrderBy
BSort
COrder
DSortBy
Attempts:
3 left
💡 Hint
Common Mistakes
Using Sort is a method on List but not in LINQ.
Order and SortBy are not valid LINQ methods.
4fill in blank
hard

Fill both blanks to create a dictionary that maps each word to its length, but only include words longer than 3 characters.

C Sharp (C#)
var wordLengths = words.Where(w => w.[1] > 3).ToDictionary(w => w, w => w.[2]);
Drag options to blanks, or click blank then click option'
ALength
BCount
CSize
DCapacity
Attempts:
3 left
💡 Hint
Common Mistakes
Using Count instead of Length for strings.
Using different properties in the two blanks.
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase words as keys and their lengths as values, including only words with length greater than 4.

C Sharp (C#)
var result = words.Where(w => w.[1] > 4).ToDictionary(w => w.[2](), w => w.[3]);
Drag options to blanks, or click blank then click option'
ACount
BLength
CToUpper
DToLower
Attempts:
3 left
💡 Hint
Common Mistakes
Using Count instead of Length for strings.
Using ToLower instead of ToUpper for keys.
Mixing properties inconsistently.