Bird
0
0

What will be the output of this C# code?

medium📝 Predict Output Q4 of 15
C Sharp (C#) - Collections
What will be the output of this C# code?
var queue = new Queue<int>();
queue.Enqueue(10);
queue.Enqueue(20);
queue.Enqueue(30);
Console.WriteLine(queue.Dequeue());
A30
B20
C10
DError
Step-by-Step Solution
Solution:
  1. Step 1: Understand Queue.Enqueue()

    Items 10, 20, 30 are added in order to the queue.
  2. Step 2: Understand Queue.Dequeue()

    Dequeue removes the first item added, which is 10.
  3. Final Answer:

    10 -> Option C
  4. Quick Check:

    Queue.Dequeue() returns first added item [OK]
Quick Trick: Dequeue returns the oldest item in Queue [OK]
Common Mistakes:
MISTAKES
  • Thinking Dequeue returns last item
  • Confusing Queue with Stack behavior

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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