Bird
0
0

Given a List numbers = new List {4, 7, 2, 9, 3}; which code snippet correctly finds the first number greater than 5 and removes it from the list?

hard🚀 Application Q15 of 15
C Sharp (C#) - Collections
Given a List numbers = new List {4, 7, 2, 9, 3}; which code snippet correctly finds the first number greater than 5 and removes it from the list?
Avar num = numbers.Find(n => n > 5); numbers.Remove(num);
Bnumbers.RemoveAt(numbers.Find(n => n > 5));
Cnumbers.Remove(numbers.FindIndex(n => n > 5));
Dnumbers.Remove(numbers.Find(n => n < 5));
Step-by-Step Solution
Solution:
  1. Step 1: Use Find to get first number > 5

    Find returns the first element matching the condition n > 5, which is 7.
  2. Step 2: Remove that number from the list

    Remove(num) deletes the first occurrence of 7 from the list.
  3. Final Answer:

    var num = numbers.Find(n => n > 5); numbers.Remove(num); -> Option A
  4. Quick Check:

    Find returns item, Remove deletes it [OK]
Quick Trick: Find returns item; Remove deletes that item [OK]
Common Mistakes:
MISTAKES
  • Passing Find result directly to RemoveAt (wrong type)
  • Using FindIndex result with Remove (expects item, not index)
  • Searching for wrong condition (n < 5 instead of n > 5)

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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