Bird
0
0

What is the issue with this C# code snippet?

medium📝 Debug Q6 of 15
C Sharp (C#) - LINQ Fundamentals

What is the issue with this C# code snippet?

var numbers = new List<int> { 4, 5, 6 };
var total = numbers.Sum;
Console.WriteLine(total);
ASum should be replaced with Count
BSum is not available for List<int>
CSum is a method and should be called with parentheses: Sum()
DThe list should be an array, not a List
Step-by-Step Solution
Solution:
  1. Step 1: Identify Sum usage

    Sum is a method and requires parentheses to invoke.
  2. Step 2: Correct the syntax

    Change numbers.Sum to numbers.Sum().
  3. Final Answer:

    Sum is a method and should be called with parentheses: Sum() -> Option C
  4. Quick Check:

    Sum() requires parentheses [OK]
Quick Trick: Sum() must be called with () [OK]
Common Mistakes:
MISTAKES
  • Using Sum without parentheses
  • Confusing Sum with property
  • Assuming Sum is not available on List

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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