StackExtensions
using System.Diagnostics.CodeAnalysis;
namespace System.Collections.Generic
{
internal static class StackExtensions
{
public static bool TryPeek<T>(this Stack<T> stack, [System.Diagnostics.CodeAnalysis.MaybeNullWhen(false)] out T result)
{
if (stack.Count > 0) {
result = stack.Peek();
return true;
}
result = default(T);
return false;
}
public static bool TryPop<T>(this Stack<T> stack, [System.Diagnostics.CodeAnalysis.MaybeNullWhen(false)] out T result)
{
if (stack.Count > 0) {
result = stack.Pop();
return true;
}
result = default(T);
return false;
}
}
}