qamp/Qrakhen.Qamp.Core/Collections/FixedArray.cs

37 lines
716 B
C#

using System.Collections;
namespace Qrakhen.Qamp.Core.Collections;
public class FixedArray<T> : IEnumerable<T>, IGetSet<long, T>
{
protected T[] Data;
public long Length => Data.LongLength;
public T this[long index] {
get => Get(index);
set => Set(index, value);
}
public FixedArray(IEnumerable<T> data)
{
Data = data.ToArray();
}
public T Get(long index) => Data[index];
public void Set(long index, T value)
{
Data[index] = value;
}
public IEnumerator<T> GetEnumerator()
{
foreach (var item in Data)
yield return item;
}
IEnumerator IEnumerable.GetEnumerator()
=> GetEnumerator();
}