Recall & Review
beginner
What does the Count aggregate function do in C#?
Count returns the total number of elements in a collection or sequence.
Click to reveal answer
beginner
How does the Sum function work in C#?
Sum adds up all the numeric values in a collection and returns the total.
Click to reveal answer
beginner
What is the purpose of the Average function in C#?
Average calculates the mean value by dividing the sum of all elements by the number of elements.
Click to reveal answer
beginner
Can Count be used on an empty collection? What is the result?
Yes, Count can be used on an empty collection and it returns 0.
Click to reveal answer
intermediate
What happens if you use Sum or Average on an empty collection in C#?
Sum returns 0 for an empty collection. Average throws an InvalidOperationException because it cannot divide by zero.
Click to reveal answer
What does the Count() method return when called on a list of 5 elements?
✗ Incorrect
Count() returns the number of elements, so for 5 elements it returns 5.
Which aggregate function would you use to find the total price of items in a shopping cart?
✗ Incorrect
Sum adds all numeric values, perfect for total price calculation.
What will Average() return when called on a collection with values {2, 4, 6}?
✗ Incorrect
Average is (2 + 4 + 6) / 3 = 4.
What happens if you call Average() on an empty list in C#?
✗ Incorrect
Average() throws InvalidOperationException because it cannot compute average of zero elements.
Which aggregate function can be safely called on an empty collection without throwing an error?
✗ Incorrect
Count returns 0 and Sum returns 0 on empty collections, both safe.
Explain how Count, Sum, and Average aggregate functions work in C# with simple examples.
Think about counting items, adding prices, and finding average scores.
You got /4 concepts.
What should you be careful about when using Average on collections in C#?
Consider what happens if there is nothing to average.
You got /3 concepts.