Bird
Raised Fist0

What will be the output of this code snippet?

medium📝 Predict Output Q5 of Q15
C Sharp (C#) - LINQ Fundamentals

What will be the output of this code snippet?

var values = new List<int> { 10, 20, 30 };
var average = values.Average();
Console.WriteLine(average);
A60
B20
C30
D10
Step-by-Step Solution
Solution:
  1. Step 1: Calculate sum of list elements

    Sum is 10 + 20 + 30 = 60.
  2. Step 2: Calculate average

    Average is sum divided by count: 60 / 3 = 20.
  3. Final Answer:

    20 -> Option B
  4. Quick Check:

    Average = Sum / Count = 20 [OK]
Quick Trick: Average = total sum divided by number of items [OK]
Common Mistakes:
MISTAKES
  • Printing sum instead of average
  • Using count as average
  • Dividing by wrong number

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Sharp (C#) Quizzes