Bird
0
0

How can you use LINQ method syntax to group a list of words by their first letter and then select the count of words in each group?

hard🚀 Application Q9 of 15
C Sharp (C#) - LINQ Fundamentals
How can you use LINQ method syntax to group a list of words by their first letter and then select the count of words in each group?
Alist.Where(w => w[0]).GroupBy(w => w).Count()
Blist.Select(w => w[0]).GroupBy().Count()
Clist.OrderBy(w => w[0]).Select(w => w.Count())
Dlist.GroupBy(w => w[0]).Select(g => new { Letter = g.Key, Count = g.Count() })
Step-by-Step Solution
Solution:
  1. Step 1: Group words by first letter

    Use GroupBy(w => w[0]) to group by first character.
  2. Step 2: Select group key and count

    Use Select(g => new { Letter = g.Key, Count = g.Count() }) to get letter and count.
  3. Final Answer:

    list.GroupBy(w => w[0]).Select(g => new { Letter = g.Key, Count = g.Count() }) -> Option D
  4. Quick Check:

    GroupBy key then select count = list.GroupBy(w => w[0]).Select(g => new { Letter = g.Key, Count = g.Count() }) [OK]
Quick Trick: GroupBy key, then Select group info [OK]
Common Mistakes:
MISTAKES
  • Misusing GroupBy without key
  • Counting before grouping
  • Using Where incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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