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

Aggregate functions (Count, Sum, Average) 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 count the number of elements in the list.

C Sharp (C#)
int count = numbers.[1]();
Drag options to blanks, or click blank then click option'
ACount
BSum
CAverage
DMax
Attempts:
3 left
💡 Hint
Common Mistakes
Using Sum() instead of Count()
Using Average() which calculates the mean
Using Max() which finds the largest value
2fill in blank
medium

Complete the code to calculate the sum of all elements in the list.

C Sharp (C#)
int total = numbers.[1]();
Drag options to blanks, or click blank then click option'
AMin
BSum
CAverage
DCount
Attempts:
3 left
💡 Hint
Common Mistakes
Using Count() which returns the number of elements
Using Average() which calculates the mean
Using Min() which finds the smallest value
3fill in blank
hard

Fix the error in the code to calculate the average of the list elements.

C Sharp (C#)
double avg = numbers.[1]();
Drag options to blanks, or click blank then click option'
AAverage
BCount
CSum
DMax
Attempts:
3 left
💡 Hint
Common Mistakes
Using Sum() which adds all elements
Using Count() which counts elements
Using Max() which finds the largest element
4fill in blank
hard

Fill both blanks to create a dictionary with words as keys and their lengths as values.

C Sharp (C#)
var lengths = new Dictionary<string, int> { { [1], [2] } };
Drag options to blanks, or click blank then click option'
Aword
Bword.Length
Cword.Length > 3
D"length"
Attempts:
3 left
💡 Hint
Common Mistakes
Using a boolean expression as a value
Using a string 'length' instead of the actual length
Using the length as key instead of value
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase words to their lengths, including only words longer than 4 characters.

C Sharp (C#)
var result = words.Where(word => word.Length [1] 4).ToDictionary([2] => [3], word => word.Length);
Drag options to blanks, or click blank then click option'
A>
Bw
Cw.ToUpper()
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' in the filter
Using the original word as key instead of uppercase
Using the wrong lambda parameter name