Bird
Raised Fist0

Which of the following is the correct syntax to remove the first occurrence of "apple" from a List named fruits?

easy📝 Syntax Q12 of Q15
C Sharp (C#) - Collections
Which of the following is the correct syntax to remove the first occurrence of "apple" from a List named fruits?
Afruits.RemoveAt("apple");
Bfruits.Delete("apple");
Cfruits.Remove("apple");
Dfruits.RemoveItem("apple");
Step-by-Step Solution
Solution:
  1. Step 1: Identify the correct method name

    The method to remove an item by value is Remove, so fruits.Remove("apple") is correct.
  2. Step 2: Check method parameters and usage

    RemoveAt requires an index, not a string. Delete and RemoveItem are not valid List methods.
  3. Final Answer:

    fruits.Remove("apple"); -> Option C
  4. Quick Check:

    Remove("apple") removes first matching item [OK]
Quick Trick: Use Remove with the item value to delete it [OK]
Common Mistakes:
MISTAKES
  • Using RemoveAt with a string argument
  • Using non-existent methods like Delete or RemoveItem
  • Confusing Remove with Add

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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