From ba54f9e3253ae8913ef286ce6e233e8fe9b82ff2 Mon Sep 17 00:00:00 2001 From: ig Date: Thu, 6 Apr 2023 14:31:19 +0200 Subject: [PATCH] add ToQueue and ToStack --- csharp/Lib/Utils/EnumerableUtils.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/csharp/Lib/Utils/EnumerableUtils.cs b/csharp/Lib/Utils/EnumerableUtils.cs index af9cc1998..609258c37 100644 --- a/csharp/Lib/Utils/EnumerableUtils.cs +++ b/csharp/Lib/Utils/EnumerableUtils.cs @@ -68,7 +68,23 @@ public static class EnumerableUtils // } + public static Queue ToQueue(this IEnumerable ts) + { + var q = new Queue(); + foreach (var t in ts) + q.Enqueue(t); + return q; + } + + public static Stack ToStack(this IEnumerable ts) + { + var s = new Stack(); + foreach (var t in ts) + s.Push(t); + + return s; + } public static async IAsyncEnumerable SelectManyAsync(this IEnumerable ts, Func>> func)