Stack
Provides various extension methods for class Stack<T>.
using System;
using System.Collections.Generic;
namespace DotNext.Collections.Generic
{
public static class Stack
{
public static Stack<T> Clone<T>(this Stack<T> original)
{
if (original.Count == 0)
return new Stack<T>();
T[] array = original.ToArray();
Array.Reverse((Array)array);
return new Stack<T>((IEnumerable<T>)array);
}
public static bool TryPeek<T>(this Stack<T> stack, out T obj)
{
if (stack.Count > 0) {
obj = stack.Peek();
return true;
}
obj = default(T);
return false;
}
public static bool TryPop<T>(this Stack<T> stack, out T obj)
{
if (stack.Count > 0) {
obj = stack.Pop();
return true;
}
obj = default(T);
return false;
}
}
}