Bird
0
0

What is the output of this C# code?

medium📝 Predict Output Q13 of 15
C Sharp (C#) - LINQ Fundamentals

What is the output of this C# code?

var numbers = new List<int> { 2, 4, 6, 8 };
var result = numbers.Average();
Console.WriteLine(result);
A20
B6
C4
D5
Step-by-Step Solution
Solution:
  1. Step 1: Calculate the sum of the list elements

    Sum = 2 + 4 + 6 + 8 = 20
  2. Step 2: Calculate the average

    Average = Sum / Count = 20 / 4 = 5.0
  3. Step 3: Check the output type

    Average returns a double, so output is 5 (printed as 5)
  4. Final Answer:

    5 -> Option D
  5. Quick Check:

    Average = 20 / 4 = 5 [OK]
Quick Trick: Average = sum of values divided by count [OK]
Common Mistakes:
MISTAKES
  • Adding values but not dividing by count
  • Confusing sum with average
  • Miscounting number of elements

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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