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

Aggregate functions (Count, Sum, Average) in C Sharp (C#) - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
A0
BAverage of elements
CSum of elements
D5
Which aggregate function would you use to find the total price of items in a shopping cart?
AAverage
BCount
CSum
DMin
What will Average() return when called on a collection with values {2, 4, 6}?
A4
B3
C12
D6
What happens if you call Average() on an empty list in C#?
AReturns 0
BThrows an exception
CReturns null
DReturns -1
Which aggregate function can be safely called on an empty collection without throwing an error?
ABoth A and C
BAverage
CSum
DCount
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.