Bird
Raised Fist0

How can you group a list of words by their first letter using LINQ query syntax?

hard🚀 Application Q9 of Q15
C Sharp (C#) - LINQ Fundamentals
How can you group a list of words by their first letter using LINQ query syntax?
Afrom w in words group w by w[0];
Bfrom w in words select w group by w[0];
Cgroup w by w[0] from words;
Dfrom words group w by w[0];
Step-by-Step Solution
Solution:
  1. Step 1: Understand grouping syntax in LINQ

    Grouping uses 'group by ' after 'from' clause.
  2. Step 2: Identify correct syntax

    from w in words group w by w[0]; correctly groups words by their first character using 'group w by w[0];'.
  3. Final Answer:

    from w in words group w by w[0]; -> Option A
  4. Quick Check:

    Group syntax: from ... group ... by ... [OK]
Quick Trick: Use 'group ... by ...' after 'from' to group in LINQ [OK]
Common Mistakes:
MISTAKES
  • Placing 'group' before 'from'
  • Using 'select' with 'group' incorrectly
  • Wrong variable order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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