using System.Linq; namespace System.Collections.Generic { public class OrderedList: IEnumerable, ICollection where T : notnull { private readonly List list = new List(); private readonly Func keySelector; private readonly bool isDescending = false; private IOrderedEnumerable OrdredList => isDescending ? list.OrderByDescending(keySelector) : list.OrderBy(keySelector); public int Count => list.Count; public bool IsReadOnly => false; public OrderedList(Func keySelector, bool isDescending = false) { this.keySelector = keySelector; this.isDescending = isDescending; } public void Add(T item) => list.Add(item); public void Clear()=> list.Clear(); public bool Contains(T item)=> list.Contains(item); public void CopyTo(T[] array, int arrayIndex)=> list.CopyTo(array, arrayIndex); public bool Remove(T item)=> list.Remove(item); public IEnumerator GetEnumerator() => OrdredList.GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } }