Bird
0
0

Find the mistake in this C# code:

medium📝 Debug Q7 of 15
C Sharp (C#) - Collections
Find the mistake in this C# code:
var stack = new Stack<string>();
stack.Push("x");
stack.Push("y");
string s = stack.Dequeue();
APush() is used incorrectly
BStack does not have a Dequeue() method
CStack cannot store strings
DMissing parentheses in Push()
Step-by-Step Solution
Solution:
  1. Step 1: Review Stack methods

    Stack uses Push() to add and Pop() to remove items, not Dequeue().
  2. Step 2: Identify incorrect method call

    Calling Dequeue() on a Stack causes a compile error because Dequeue() is a Queue method.
  3. Final Answer:

    Stack does not have a Dequeue() method -> Option B
  4. Quick Check:

    Stack removal method = Pop(), not Dequeue() [OK]
Quick Trick: Use Pop() for Stack removal, not Dequeue() [OK]
Common Mistakes:
MISTAKES
  • Using Dequeue() on Stack
  • Confusing Stack and Queue methods

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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