Issue
In C#, how can I check if a Queue is empty?
I want to iterate through the Queue's elements, and I need to know when to stop. How can I accomplish this?
Solution
Assuming you mean Queue<T>
you could just use:
if (queue.Count != 0)
But why bother? Just iterate over it anyway, and if it's empty you'll never get into the body:
Queue<string> queue = new Queue<string>();
// It's fine to use foreach...
foreach (string x in queue)
{
// We just won't get in here...
}
Answered By - Jon Skeet Answer Checked By - Mary Flores (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.