Bird
Raised Fist0

What will be printed by this C# code?

medium📝 Predict Output Q5 of Q15
C Sharp (C#) - Collections
What will be printed by this C# code?
var numbers = new List {4, 7, 2, 9};
int found = numbers.Find(x => x > 5);
Console.WriteLine(found);
A4
B7
C2
D9
Step-by-Step Solution
Solution:
  1. Step 1: Understand Find with condition x > 5

    Find returns the first element greater than 5. The list is {4,7,2,9}.
  2. Step 2: Identify first element > 5

    4 is not > 5, 7 is > 5, so Find returns 7.
  3. Final Answer:

    7 -> Option B
  4. Quick Check:

    Find first > 5 = 7 [OK]
Quick Trick: Find returns first matching element only [OK]
Common Mistakes:
MISTAKES
  • Choosing first element always
  • Picking last element > 5
  • Confusing Find with Sort

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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