Bird
Raised Fist0

Find the issue in this C# code:

medium📝 Debug Q7 of Q15
C Sharp (C#) - LINQ Fundamentals
Find the issue in this C# code:
var items = new[] {"cat", "dog", "cow"};
var grouped = items.GroupBy();
foreach (var group in grouped)
{
    Console.WriteLine(group.Key);
}
AGroupBy requires a key selector function
BGroupBy cannot be called on arrays
Cgroup.Key is not accessible
DMissing semicolon after GroupBy
Step-by-Step Solution
Solution:
  1. Step 1: Check GroupBy method call

    GroupBy requires a key selector lambda or delegate; calling without arguments is invalid.
  2. Step 2: Confirm other parts

    Arrays support GroupBy, group.Key is accessible, and semicolon is present.
  3. Final Answer:

    GroupBy requires a key selector function -> Option A
  4. Quick Check:

    GroupBy needs a key selector lambda [OK]
Quick Trick: Always provide a key selector to GroupBy [OK]
Common Mistakes:
MISTAKES
  • Calling GroupBy without parameters
  • Confusing GroupBy with other methods
  • Ignoring compiler errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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