Bird
0
0

What will be the output of this code?

medium📝 Predict Output Q5 of 15
C Sharp (C#) - LINQ Fundamentals
What will be the output of this code?
var words = new List<string> {"apple", "banana", "cherry"};
var result = words.Select(w => w.Length).OrderBy(len => len).ToList();
Console.WriteLine(string.Join("-", result));
A7-6-5
B6-6-5
C5-6-7
D5-6-6
Step-by-Step Solution
Solution:
  1. Step 1: Select lengths of each word

    "apple"=5, "banana"=6, "cherry"=6.
  2. Step 2: Order lengths ascending

    Sorted lengths are 5, 6, 6.
  3. Step 3: Join with dashes

    Output is "5-6-6".
  4. Final Answer:

    5-6-6 -> Option D
  5. Quick Check:

    Select lengths then order = 5-6-6 [OK]
Quick Trick: Select projects, OrderBy sorts ascending [OK]
Common Mistakes:
MISTAKES
  • Assuming OrderBy sorts descending
  • Mixing word lengths
  • Incorrect join separator

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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