<PackageReference Include="System.Text.Json" Version="5.0.0-rc.1.20451.14" />

StackExtensions

static class 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; } } }