Bird
Raised Fist0

Which of the following is the correct way to add an item to a Stack in C#?

easy📝 Syntax Q12 of Q15
C Sharp (C#) - Collections
Which of the following is the correct way to add an item to a Stack in C#?
Astack.Push(item);
Bstack.Enqueue(item);
Cstack.Add(item);
Dstack.Insert(item);
Step-by-Step Solution
Solution:
  1. Step 1: Recall Stack method names

    In C#, Stack uses Push() to add items on top.
  2. Step 2: Identify correct method

    Enqueue is for Queue, Add and Insert are not Stack methods.
  3. Final Answer:

    stack.Push(item); -> Option A
  4. Quick Check:

    Push adds to Stack [OK]
Quick Trick: Use Push() to add to Stack, Enqueue() for Queue [OK]
Common Mistakes:
MISTAKES
  • Using Enqueue() on Stack
  • Using Add() or Insert() which don't exist
  • Confusing Stack and Queue methods
  • Syntax errors with method calls

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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