arraylist.cs
来自「没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没」· CS 代码 · 共 2,722 行 · 第 1/4 页
CS
2,722 行
throw new NotSupportedException(_("NotSupp_ReadOnly")); } public override void Sort(int index, int count, IComparer comparer) { throw new NotSupportedException(_("NotSupp_ReadOnly")); } // Trim the array list to its actual size. public override void TrimToSize() { throw new NotSupportedException(_("NotSupp_ReadOnly")); } // Get or set the current capacity of the array list. public override int Capacity { get { return list.Capacity; } set { throw new NotSupportedException(_("NotSupp_ReadOnly")); } } }; // class ReadOnlyWrapper#if !ECMA_COMPAT // Adapt an ordinary list to appear to be read-only. public static IList ReadOnly(IList list) { if(list == null) { throw new ArgumentNullException("list"); } else { return new ReadOnlyListWrapper(list); } } // Wrapper class for read-only lists. private sealed class ReadOnlyListWrapper : IList { // Internal state. private IList list; // Constructor. public ReadOnlyListWrapper(IList list) { this.list = list; } // Implement the IList interface. public int Add(Object value) { throw new NotSupportedException (_("NotSupp_ReadOnly")); } public void Clear() { throw new NotSupportedException (_("NotSupp_ReadOnly")); } 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_ReadOnly")); } public void Remove(Object value) { throw new NotSupportedException (_("NotSupp_ReadOnly")); } public void RemoveAt(int index) { throw new NotSupportedException (_("NotSupp_ReadOnly")); } public bool IsFixedSize { get { return list.IsFixedSize; } } public bool IsReadOnly { get { return true; } } public Object this[int index] { get { return list[index]; } set { throw new NotSupportedException (_("NotSupp_ReadOnly")); } } // 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 ReadOnlyListWrapper#endif // !ECMA_COMPAT // Adapt an array list to appear to be synchonrized public static ArrayList Synchronized(ArrayList list) { if(list == null) { throw new ArgumentNullException("list"); } else if(list.IsSynchronized) { return list; } else { return new SynchronizedWrapper(list); } } // Wrapper class for synchronized lists. private class SynchronizedWrapper : ArrayList { // Internal state. private ArrayList list; // Constructor. public SynchronizedWrapper(ArrayList list) { this.list = list; } // Implement the IList interface. public override int Add(Object value) { lock(SyncRoot) { return list.Add(value); } } public override void Clear() { lock(SyncRoot) { list.Clear(); } } public override bool Contains(Object item) { lock(SyncRoot) { return list.Contains(item); } } public override int IndexOf(Object value) { lock(SyncRoot) { return list.IndexOf(value); } } public override void Insert(int index, Object value) { lock(SyncRoot) { list.Insert(index, value); } } public override void Remove(Object value) { lock(SyncRoot) { list.Remove(value); } } public override void RemoveAt(int index) { lock(SyncRoot) { list.RemoveAt(index); } } public override bool IsFixedSize { get { lock(SyncRoot) { return list.IsFixedSize; } } } public override bool IsReadOnly { get { lock(SyncRoot) { return list.IsReadOnly; } } } public override Object this[int index] { get { lock(SyncRoot) { return list[index]; } } set { lock(SyncRoot) { list[index] = value; } } } // Range-related methods. public override void AddRange(ICollection c) { lock(SyncRoot) { list.AddRange(c); } } public override void InsertRange(int index, ICollection c) { lock(SyncRoot) { list.InsertRange(index, c); } } public override void RemoveRange(int index, int count) { lock(SyncRoot) { list.RemoveRange(index, count); } } public override void SetRange(int index, ICollection c) { lock(SyncRoot) { list.SetRange(index, c); } } // Searching methods. public override int BinarySearch(Object value) { lock(SyncRoot) { return list.BinarySearch(value); } } public override int BinarySearch(Object value, IComparer comparer) { lock(SyncRoot) { return list.BinarySearch(value, comparer); } } public override int BinarySearch(int index, int count, Object value, IComparer comparer) { lock(SyncRoot) { return list.BinarySearch(index, count, value, comparer); } } public override int IndexOf(Object value, int startIndex) { lock(SyncRoot) { return list.IndexOf(value, startIndex); } } public override int IndexOf(Object value, int startIndex, int count) { lock(SyncRoot) { return list.IndexOf(value, startIndex, count); } } public override int LastIndexOf(Object value) { lock(SyncRoot) { return list.LastIndexOf(value); } } public override int LastIndexOf(Object value, int startIndex) { lock(SyncRoot) { return list.LastIndexOf(value, startIndex); } } public override int LastIndexOf(Object value, int startIndex, int count) { lock(SyncRoot) { return list.LastIndexOf(value, startIndex, count); } } // Implement the ICollection interface. public override void CopyTo(Array array, int arrayIndex) { lock(SyncRoot) { list.CopyTo(array, arrayIndex); } } public override int Count { get { lock(SyncRoot) { return list.count; } } } public override bool IsSynchronized { get { return true; } } public override Object SyncRoot { get { return list.SyncRoot; } } // Copy from this array list to another array. public override void CopyTo(Array array) { lock(SyncRoot) { list.CopyTo(array); } } public override void CopyTo(int index, Array array, int arrayIndex, int count) { lock(SyncRoot) { list.CopyTo(index, array, arrayIndex, count); } } // Reverse the contents of this array list. public override void Reverse() { lock(SyncRoot) { list.Reverse(); } } public override void Reverse(int index, int count) { lock(SyncRoot) { list.Reverse(index, count); } } // Sort the contents of this array list. public override void Sort() { lock(SyncRoot) { list.Sort(); } } public override void Sort(IComparer comparer) { lock(SyncRoot) { list.Sort(comparer); } } public override void Sort(int index, int count, IComparer comparer) { lock(SyncRoot) { list.Sort(index, count, comparer); } } // Create an array that contains the elements of this array list. public override Object[] ToArray() { lock(SyncRoot) { return list.ToArray(); } } public override Array ToArray(Type type) { lock(SyncRoot) { return list.ToArray(type); } } // Trim the array list to its actual size. public override void TrimToSize() { lock(SyncRoot) { list.TrimToSize(); } } // Get or set the current capacity of the array list. public override int Capacity { get { lock(SyncRoot) { return list.Capacity; } } set { lock(SyncRoot) { list.Capacity = value; } } } // Get an enumerator for this array list. public override IEnumerator GetEnumerator() { lock(SyncRoot) { return new SynchronizedEnumerator (SyncRoot, list.GetEnumerator()); } } public override IEnumerator GetEnumerator(int index, int count) { lock(SyncRoot) { return new SynchronizedEnumerator (SyncRoot, list.GetEnumerator(index, count)); } } }; // class SynchronizedWrapper#if !ECMA_COMPAT // Adapt an ordinary list to appear to be synchronized. public static IList Synchronized(IList list) { if(list == null) { throw new ArgumentNullException("list"); } else { return new SynchronizedListWrapper(list); } } // Wrapper class for synchronized lists. private sealed class SynchronizedListWrapper : IList { // Internal state. private IList list; // Constructor. public SynchronizedListWrapper(IList list) { this.list = list; } // Implement the IList interface. public int Add(Object value) { lock(SyncRoot) { return list.Add(value); } } public void Clear() { lock(SyncRoot) { list.Clear(); } } public bool Contains(Object value) { lock(SyncRoot) { return list.Contains(value); } } public int IndexOf(Object value) { lock(SyncRoot) { return list.IndexOf(value); } } public void Insert(int index, Object value) { lock(SyncRoot) { list.Insert(index, value); } } public void Remove(Object value) { lock(SyncRoot) { list.Remove(value); } } public void RemoveAt(int index) { lock(SyncRoot) { list.RemoveAt(index); } } public bool IsFixedSize { get { lock(SyncRoot) { return list.IsFixedSize; } } } public bool IsReadOnly { get { lock(SyncRoot) { return list.IsReadOnly; } } } public Object this[int index] { get { lock(SyncRoot) { return list[index]; } } set { lock(SyncRoot) { list[index] = value; } } } // Implement the ICollection interface. public void CopyTo(Array array, int index) { lock(SyncRoot) { list.CopyTo(array, index); } } public int Count { get { lock(SyncRoot) { return list.Count; } } } public bool IsSynchronized { get { return true; } } public Object SyncRoot { get { return list.SyncRoot; } } // Implement the IEnumerable interface. public IEnumerator GetEnumerator() { lock(SyncRoot) { return new SynchronizedEnumerator (SyncRoot, list.GetEnumerator()); } } }; // class SynchronizedListWrapper#endif // !ECMA_COMPAT}; // class ArrayList}; // namespace System.Collections
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?