arraylist.cs
来自「没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没」· CS 代码 · 共 2,722 行 · 第 1/4 页
CS
2,722 行
public override int Capacity { get { return list.Capacity; } set { list.Capacity = value; } } // Get an enumerator for this array list. public override IEnumerator GetEnumerator() { return list.GetEnumerator(); } public override IEnumerator GetEnumerator(int index, int count) { return list.GetEnumerator(index, count); } }; // class PassThroughWrapper // Adapt an array list to appear to have a fixed size. public static ArrayList FixedSize(ArrayList list) { if(list == null) { throw new ArgumentNullException("list"); } else if(list.IsFixedSize) { return list; } else { return new FixedSizeWrapper(list); } } // Wrapper class for fixed size lists. private class FixedSizeWrapper : PassThroughWrapper { public FixedSizeWrapper(ArrayList list) : base(list) { } // Implement the IList interface. public override int Add(Object value) { throw new NotSupportedException (_("NotSupp_FixedSizeCollection")); } public override void Clear() { throw new NotSupportedException (_("NotSupp_FixedSizeCollection")); } public override void Insert(int index, Object value) { throw new NotSupportedException (_("NotSupp_FixedSizeCollection")); } public override void Remove(Object value) { throw new NotSupportedException (_("NotSupp_FixedSizeCollection")); } public override void RemoveAt(int index) { throw new NotSupportedException (_("NotSupp_FixedSizeCollection")); } public override bool IsFixedSize { get { return true; } } public override bool IsReadOnly { get { return list.IsReadOnly; } } public override Object this[int index] { get { return list[index]; } set { list[index] = value; } } // Range-related methods. public override void AddRange(ICollection c) { throw new NotSupportedException (_("NotSupp_FixedSizeCollection")); } public override void InsertRange(int index, ICollection c) { throw new NotSupportedException (_("NotSupp_FixedSizeCollection")); } public override void RemoveRange(int index, int count) { throw new NotSupportedException (_("NotSupp_FixedSizeCollection")); } // Implement the ICloneable interface. public override Object Clone() { return new FixedSizeWrapper((ArrayList)(list.Clone())); } // Trim the array list to its actual size. public override void TrimToSize() { throw new NotSupportedException (_("NotSupp_FixedSizeCollection")); } }; // class FixedSizeWrapper#if !ECMA_COMPAT // Adapt an ordinary list to appear to have a fixed size. public static IList FixedSize(IList list) { if(list == null) { throw new ArgumentNullException("list"); } else { return new FixedSizeListWrapper(list); } } // Wrapper class for fixed-sized lists. private sealed class FixedSizeListWrapper : IList { // Internal state. private IList list; // Constructor. public FixedSizeListWrapper(IList list) { this.list = list; } // Implement the IList interface. public int Add(Object value) { throw new NotSupportedException (_("NotSupp_FixedSizeCollection")); } public void Clear() { throw new NotSupportedException (_("NotSupp_FixedSizeCollection")); } public bool Contains(Object value) { return list.Contains(value); } public int IndexOf(Object value) { return list.IndexOf(value); } public void Insert(int index, Object value) { throw new NotSupportedException (_("NotSupp_FixedSizeCollection")); } public void Remove(Object value) { throw new NotSupportedException (_("NotSupp_FixedSizeCollection")); } public void RemoveAt(int index) { throw new NotSupportedException (_("NotSupp_FixedSizeCollection")); } public bool IsFixedSize { get { return true; } } public bool IsReadOnly { get { return list.IsReadOnly; } } public Object this[int index] { get { return list[index]; } set { list[index] = value; } } // Implement the ICollection interface. public void CopyTo(Array array, int index) { list.CopyTo(array, index); } public int Count { get { return list.Count; } } public bool IsSynchronized { get { return list.IsSynchronized; } } public Object SyncRoot { get { return list.SyncRoot; } } // Implement the IEnumerable interface. public IEnumerator GetEnumerator() { return list.GetEnumerator(); } }; // class FixedSizeListWrapper#endif // !ECMA_COMPAT // Adapt an array list to get access to a sub-range. public virtual ArrayList GetRange(int index, int count) { if(index < 0) { throw new ArgumentOutOfRangeException ("index", _("ArgRange_Array")); } if(count < 0) { throw new ArgumentOutOfRangeException ("count", _("ArgRange_Array")); } if((this.count - index) < count) { throw new ArgumentException(_("Arg_InvalidArrayRange")); } return new RangeWrapper(this, index, count); } // Wrapper class for sub-range array lists. private class RangeWrapper : ArrayList { private ArrayList list; private int index; private new int count; public RangeWrapper(ArrayList list, int index, int count) : base(list) { this.list = list; this.index = index; this.count = count; generation = list.generation; } // Determine if the underlying array list has been changed. private void UnderlyingCheck() { if(generation != list.generation) { throw new InvalidOperationException (_("Invalid_UnderlyingModified")); } } // Implement the IList interface. public override int Add(Object value) { UnderlyingCheck(); list.Insert(index + count, value); generation = list.generation; return index + count; } public override void Clear() { UnderlyingCheck(); list.Clear(); generation = list.generation; } public override bool Contains(Object item) { UnderlyingCheck(); return (list.IndexOf(item) != -1); } public override int IndexOf(Object value) { UnderlyingCheck(); return list.IndexOf(value, index, count); } public override void Insert(int index, Object value) { UnderlyingCheck(); if(index < 0 || index >= count) { throw new ArgumentOutOfRangeException ("index", _("ArgRange_Array")); } list.Insert(index + this.index, value); generation = list.generation; } public override void Remove(Object value) { UnderlyingCheck(); int ind = list.IndexOf(value, index, count); if(ind != -1) { list.RemoveAt(ind); } generation = list.generation; } public override void RemoveAt(int index) { UnderlyingCheck(); list.RemoveAt(index + this.index); generation = list.generation; } public override bool IsFixedSize { get { return list.IsFixedSize; } } public override bool IsReadOnly { get { return list.IsReadOnly; } } public override Object this[int index] { get { UnderlyingCheck(); if(index < 0 || index >= count) { throw new ArgumentOutOfRangeException ("index", _("ArgRange_Array")); } return list[index + this.index]; } set { UnderlyingCheck(); if(index < 0 || index >= count) { throw new ArgumentOutOfRangeException ("index", _("ArgRange_Array")); } list[index + this.index] = value; generation = list.generation; } } // Range-related methods. public override void AddRange(ICollection c) { UnderlyingCheck(); list.InsertRange(index + count, c); generation = list.generation; } public override void InsertRange(int index, ICollection c) { UnderlyingCheck(); list.InsertRange(index + this.index, c); generation = list.generation; } public override void RemoveRange(int index, int count) { UnderlyingCheck(); list.RemoveRange(index + this.index, count); generation = list.generation; } public override void SetRange(int index, ICollection c) { UnderlyingCheck(); list.SetRange(index + this.index, c); generation = list.generation; } // Implement the ICloneable interface. public override Object Clone() { return new RangeWrapper ((ArrayList)(list.Clone()), index, count); } // Searching methods. public override int BinarySearch(Object value) { UnderlyingCheck(); return list.BinarySearch (index, count, value, (IComparer)null); } public override int BinarySearch(Object value, IComparer comparer) { UnderlyingCheck(); return list.BinarySearch(index, count, value, comparer); } public override int BinarySearch(int index, int count, Object value, IComparer comparer) { UnderlyingCheck(); return list.BinarySearch(index + this.index, count, value, comparer); } public override int IndexOf(Object value, int startIndex) { UnderlyingCheck(); return list.IndexOf(value, startIndex); } public override int IndexOf(Object value, int startIndex, int count) { UnderlyingCheck(); return list.IndexOf(value, startIndex, count); } public override int LastIndexOf(Object value) { UnderlyingCheck(); return list.LastIndexOf(value); } public override int LastIndexOf(Object value, int startIndex) { UnderlyingCheck(); return list.LastIndexOf(value, startIndex); } public override int LastIndexOf(Object value, int startIndex, int count) { UnderlyingCheck(); return list.LastIndexOf(value, startIndex, count); } // Implement the ICollection interface. public override void CopyTo(Array array, int arrayIndex) { list.CopyTo(array, arrayIndex); } public override int Count { get { UnderlyingCheck(); return count; } } public override bool IsSynchronized { get { return list.IsSynchronized; } } public override Object SyncRoot { get { return list.SyncRoot; } } // Copy from this array list to another array. public override void CopyTo(Array array) { list.CopyTo(array); } public override void CopyTo(int index, Array array, int arrayIndex, int count) { list.CopyTo(index, array, arrayIndex, count); } // Reverse the contents of this array list. public override void Reverse() { list.Reverse(); } public override void Reverse(int index, int count) { list.Reverse(index, count); } // Sort the contents of this array list. public override void Sort() { list.Sort(); } public override void Sort(IComparer comparer) { list.Sort(comparer); } public override void Sort(int index, int count, IComparer comparer) { list.Sort(index, count, comparer); } // Create an array that contains the elements of this array list. public override Object[] ToArray() { return list.ToArray(); } public override Array ToArray(Type type) { return list.ToArray(type); } // Trim the array list to its actual size. public override void TrimToSize() { list.TrimToSize(); } // Get or set the current capacity of the array list. public override int Capacity { get { return list.Capacity; } set { list.Capacity = value; } } // Get an enumerator for this array list. public override IEnumerator GetEnumerator() { return list.GetEnumerator(); } public override IEnumerator GetEnumerator(int index, int count) { return list.GetEnumerator(index, count); } }; // class RangeWrapper // Adapt an array list to appear to be read-only. public static ArrayList ReadOnly(ArrayList list) { if(list == null) { throw new ArgumentNullException("list"); } else if(list.IsReadOnly) { return list; } else { return new ReadOnlyWrapper(list); } } // Wrapper class for read-only lists. private class ReadOnlyWrapper : PassThroughWrapper { public ReadOnlyWrapper(ArrayList list) : base(list) { } // Implement the IList interface. public override int Add(Object value) { throw new NotSupportedException(_("NotSupp_ReadOnly")); } public override void Clear() { throw new NotSupportedException(_("NotSupp_ReadOnly")); } public override void Insert(int index, Object value) { throw new NotSupportedException(_("NotSupp_ReadOnly")); } public override void Remove(Object value) { throw new NotSupportedException(_("NotSupp_ReadOnly")); } public override void RemoveAt(int index) { throw new NotSupportedException(_("NotSupp_ReadOnly")); } public override bool IsReadOnly { get { return true; } } public override Object this[int index] { get { return list[index]; } set { throw new NotSupportedException(_("NotSupp_ReadOnly")); } } // Range-related methods. public override void AddRange(ICollection c) { throw new NotSupportedException(_("NotSupp_ReadOnly")); } public override void InsertRange(int index, ICollection c) { throw new NotSupportedException(_("NotSupp_ReadOnly")); } public override void RemoveRange(int index, int count) { throw new NotSupportedException(_("NotSupp_ReadOnly")); } public override void SetRange(int index, ICollection c) { throw new NotSupportedException(_("NotSupp_ReadOnly")); } // Implement the ICloneable interface. public override Object Clone() { return new ReadOnlyWrapper((ArrayList)(list.Clone())); } // Reverse the contents of this array list. public override void Reverse() { throw new NotSupportedException(_("NotSupp_ReadOnly")); } public override void Reverse(int index, int count) { throw new NotSupportedException(_("NotSupp_ReadOnly")); } // Sort the contents of this array list. public override void Sort() { throw new NotSupportedException(_("NotSupp_ReadOnly")); } public override void Sort(IComparer comparer) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?