diff --git a/Collections/RingBuffer.cs b/Collections/RingBuffer.cs index 4977375..959d870 100644 --- a/Collections/RingBuffer.cs +++ b/Collections/RingBuffer.cs @@ -1,4 +1,6 @@ using System; +using System.Collections; +using System.Collections.Generic; using Exanite.Core.Utilities; namespace Exanite.Core.Collections @@ -6,7 +8,7 @@ namespace Exanite.Core.Collections /// /// Represents a fixed-sized circular queue. /// - public class RingBuffer + public class RingBuffer : IEnumerable { private readonly T[] data; private readonly int capacityMask; @@ -146,5 +148,18 @@ public bool TryPeek(out T? value) value = data[capacityMask & readOffset]; return true; } + + public IEnumerator GetEnumerator() + { + for (var i = 0; i < Count; i++) + { + yield return this[i]; + } + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } } }