COLLECTIONBASE class

xiaoxiao2021-03-06  111

COLLECTIONBASE class

See

CollectionBase Member | System.Collections Namespace | System.Collections.ArrayList | System.collections.ilist | ReadonlyCollectionBase |

Execute string operations in different partition domain

CollectionBase Member (Visual J # Syntax) | C Hosting Extension Programming

Claim

Name Space: System.collections

Platform: Windows 98, Windows NT 4.0, Windows Me, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 Series, .NET Framework Lite - Windows CE .NET

Accessure: Mscorlib (in Mscorlib.dll)

Abstract (Mustinherit in Visual Basic) is provided for a strong type collection.

For a list of all members of this type, see the CollectionBase member.

System.Object System.collections.collectionBase Derivenies

[C #]

[Serializable]

Public Abstract Class CollectionBase: IList, Icollection,

Ienumerable

Thread security

This type of public static (shared in Visual Basic) is safe for multi-threaded operations. Unable to ensure that instance members are threads.

This implementation does not provide synchronous (thread security) packages for CollectionBase, but derived classes can use the syncroot attribute to create their own CollectionBase sync.

By collecting enumerations in nature is not a thread safe process. Even when synchronizing the collection, other threads can still modify the collection, which will cause an enumeration number to trigger an exception. To ensure thread security during enumeration, you can lock a collection throughout the enumeration process or capture an exception that caused by other threads.

Note

The CollectionBase instance is always modified. See READOONLYCOLLECTIONBASE for this class.

For the implementator's instructions: Provide this base class to make the implementer to create a strong type of custom set easier. The implementator should expand this class without creating its own base class.

Example

[C #] using system.collections;

Public Class Int16Collection: CollectionBase {

Public INT16 this [int index] {get {return ((int16) list [index]);} set {list [index] = value;}}

Public Int Add (INT16 Value) {Return (List.Add (Value));

Public int indexof (INT16 VALUE) {Return (list.indexof (value));}

Public void insert (int index, int16 value) {list.insert (index, value);

Public void remove (INT16 VALUE) {list.remove (value);} public bool contacts {// if value is not of type INT16, this will return false. Return (List.Contains (Value));}

Protected Override Void OnInsert (INDEX, Object Value) {if (Value.gettype ()! = Type.getType ("System.INT16")) Throw new ArgumentException ("Value Must Be of Type Int16," Value ") }

protected override void OnRemove (int index, Object value) {if (value.GetType ()! = Type.GetType ( "System.Int16")) throw new ArgumentException ( "value must be of type Int16.", "value") }

protected override void OnSet (int index, Object oldValue, Object newValue) {if (newValue.GetType ()! = Type.GetType ( "System.Int16")) throw new ArgumentException ( "newValue must be of type Int16.", " NewValue ");

Protected Override Void OnValidate (Object Value) {if (value.gettype ()! = type.gettype ("system.int16")) throw new argumentException

}

Public class samplescollectionbase {

Public static void main () {// creates and initializes a new collection name. int16collection myi16 = new int16collection ();

// Adds elements to the collection. Myi16.add ((INT16) 1); myi16.add ((int16) 2); myi16.add ((INT16) 3); myi16.add ((INT16) 5); myi16. Add ((INT16) 7);

// displays the contents of the collection using the enumerator. Console.writeline ("Initial Contents of The Collection:"); PrintIndexandVALUES (MYI16);

// Searches The Collection with contacts and indexof. Console.writeline ("Contains 3: {0}", Myi16.Contains (3)); console.writeline ("2 is at index {0}.", Myi16.indexof 2)); console.writeline (); // INSERTS An Element Into the Collection At Index 3. Myi16.insert (3, (INT16) 13); console.writeline ("Contents of the CollectionAfter Inserting At Index 3:" PrintExandVALUES (Myi16);

// Gets and sets an element using the index. Myi16 [4] = 123; console.writeline ("Contents of the CollectionAfter Setting The Element At Index 4 to 123:"); PrintIndexandValues ​​(myi16);

// removes an element from the collection. Myi16.remove ((INT16) 2);

// displays the contents of the collection using the index. Console.writeline ("Contents of the CollectionAfter Removing The Element 2:"); for (int i = 0; i

} Public static void PrintIndexAndValues ​​(Int16Collection myCol) {int i = 0; System.Collections.IEnumerator myEnumerator = myCol.GetEnumerator (); while (myEnumerator.MoveNext ()) Console.WriteLine ( "[{0}]: {1} ", i , myenumerator.current; console.writeline ();}}

/ * This Code Produces The Following Output.

Initial Contents of the Collection: [0]: 1 [1]: 2 [2]: 3 [3]: 5 [4]: ​​7

Contains 3: True2 is at index 1.

Contents of the collection after inserting at index 3: [0]: 1 [1]: 2 [2]: 3 [3]: 13 [4]: ​​5 [5]: 7

Contents of the collection after setting the element at index 4 to 123: [0]: 1 [1]: 2 [2]: 3 [3]: 13 [4]: ​​123 [5]: 7Contents of the CollectionAfter Removing the ELEMENT 2: [0]: 1 [1]: 3 [2]: 13 [3]: 123 [4]: ​​7

* /

CollectionBase Overview

Public property

COUNT is supported by .NET Framework. Get the number of elements contained in the CollectionBase instance.

Public approach

Clear is supported by the .NET Framework. Remove all objects from the CollectionBase instance. Equals (inherited from Object) is supported by .NET Framework. Overloaded. Determine if the two Object instances are equal. GetENUMERATOR is supported by .NET Framework. Returns the number of enumerations that can be cyclically accessing the CollectionBase instance. GetHashcode (inherited from Object) is supported by .NET Framework. Used as a specific type of hash function, suitable for use in a hash algorithm and data structure (such as a hash table). Gettype (inherited from Object) is supported by .NET Framework. Get the current instance of TYPE. Removeat is supported by the .NET Framework. Remove the elements at the specified index of the CollectionBase instance. TOSTRING (inherited from Object) is supported by the .NET Framework. Returns the String that represents the current Object.

Protected constructor

The CollectionBase constructor is supported by the .NET Framework. New instances of the COLLECTIONBASE class.

Protected properties

InnerList is supported by the .NET Framework. Get an ArrayList that contains a list of elements in the CollectionBase instance. List is supported by the .NET Framework. Get an IList that contains a list of elements in the CollectionBase instance.

Protected method

Finalize (inherited from Object) is supported by the .NET Framework. Override. Allow Object to try to release resources and perform other cleaning operations before "garbage recycling" recycle Object. In C # and C , the terminator is used to represent the termination program. MEMBERWISECLONE (inherited from Object) is supported by .NET Framework. Create a shallow copy of the current Object. Onclear is supported by the .NET Framework. Perform additional custom processes when the contents of the CollectionBase instance are cleared. OnclearComplete is supported by the .NET Framework. Do other custom processes after clearing the contents of the CollectionBase instance. OnInsert is supported by the .NET Framework. Perform another custom process before inserting a new element into the CollectionBase instance. OnInsertComplete is supported by the .NET Framework. Do other custom processes after inserting new elements into the CollectionBase instance. OnRemove is supported by .NET Framework. Other custom processes are performed when an element is removed from a CollectionBase instance. OnRemoveComplete is supported by the .NET Framework. Perform additional custom processes after removing elements from the CollectionBase instance. Onset is supported by the .NET Framework. Other custom processes are performed before setting values ​​in the CollectionBase instance. OnSetComplete is supported by the .NET Framework. Other custom processes are performed after setting values ​​in the CollectionBase instance. OnValidate is supported by the .NET Framework. Other custom processes are performed when validates. Explicit interface implementation

Icollection.copyTo starts copying the entire CollectionBase to a compatible one-dimensional Array from the specified index of the target array. IList.Add adds an object to the end of CollectionBase. IList.Contains determines if the CollectionBase contains a specific element. IList.Indexof searches for specified object and returns an index from zero from zero the first match in CollectionBase. IList.insert is inserted into the specified index of CollectionBase. IList.Remove removes the first match of a specific object from CollectionBase. System.Collections.icollection.issynchronized Gets the value for indicating whether synchronous CollectionBase Access (thread security). System.collections.icollection.Syncroot Gets an object that can be used to synchronize CollectionBase access. System.Collections.ilist.isFixedSize Gets a value indicating whether the CollectionBase has a fixed size. System.collections.ilist.isreadOnly Gets a value for indicating whether CollectionBase is read-only. System.collections.ilist.Item Gets or sets the elements at the specified index.

转载请注明原文地址:https://www.9cbs.com/read-97353.html

New Post(0)