using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; namespace Tool { ///where T : class 使用的泛型只能是类 ,删除这句话,可以是任何类型 public class MyList<T> : IEnumerable where T : class { public T this[int index] { get { return Ts[index]; } } ; ]; public int Add(T t) { if (Count == Ts.Length) { T[] Tstemp = ]; ; i < Ts.Length; i++) { Tstemp[i] = Ts[i]; } Ts = Tstemp; } Ts[Count] = t; Count++; return Count; } //public IEnumerator GetEnumerator() //{ // return Ts.GetEnumerator(); //} public IEnumerator GetEnumerator() { ; i < Count; i++) { yield return Ts[i]; } } public delegate TResult MyFunc<in T, out TResult>(T arg); public IEnumerable<T> Where(MyFunc<T, bool> predicate) { ; i < Count; i++) { if (!predicate.Invoke(Ts[i])) { continue; } yield return Ts[i]; } } public T Find(MyFunc<T, bool> predicate) { ; i < Count; i++) { if (predicate.Invoke(Ts[i])) { return Ts[i]; } } return Activator.CreateInstance<T>(); } public bool RomveAt(int index) { try { ; i++) { Ts[i] = Ts[i + ]; } Count--; return true; } catch (Exception) { throw; } } public void Insert(int index, T item) { if (Ts.Length == Count) { T[] Tstemp = ]; ; i < Ts.Length; i++) { Tstemp[i] = Ts[i]; } Ts = Tstemp; } T temp = Ts[index]; for (int i = Count; i >= index; i--) { Ts[i + ] = Ts[i]; } Ts[index] = item; Count++; } } }