Try Dequeue - CSharp Collection

CSharp examples for Collection:Queue

Description

Try Dequeue

Demo Code


using System.Threading.Tasks;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;/*w ww  . jav  a2  s.  c o m*/

public class Main{
        public static bool TryDequeue<T>(this Queue<T> queue, out T result)
        {
            if (queue.Count == 0)
            {
                result = default(T);
                return false;
            }
            try
            {
                result = queue.Dequeue();
                return true;
            }
            catch (Exception)
            {
                result = default(T);
                return false;
            }            
        }
}

Related Tutorials