GOA - System.Collections.CollectionBase

CollectionBase Class


Provides the abstract base class for a strongly typed collection.

Definition

public abstract class CollectionBase: Object, IList, ICollection, IEnumerable

Members Table

MethodDescription
AddWhen implemented by a class, adds an item to the IList. (Inherited from IList)
ClearRemoves all objects from the CollectionBase instance.
CollectionBaseInitializes a new instance of CollectionBase.
ContainsWhen implemented by a class, determines whether the IList contains a specific value. (Inherited from IList)
CopyToWhen implemented by a class, copies the elements of the ICollection into an Array, starting at a particular Array index. (Inherited from ICollection)
EqualsOverloaded. Compares two objects to determine if they are equal. (Inherited from Object)
GetEnumeratorReturns an enumerator that can iterate through the CollectionBase instance.
GetHashCodeServes as a hash function for a particular type, suitable for use in hashing algorithms and data structures like a hash table. (Inherited from Object)
GetTypeGets the Type of the current instance. (Inherited from Object)
IndexOfWhen implemented by a class, determines the index of a specific item in the IList. (Inherited from IList)
InsertWhen implemented by a class, inserts an item to the IList at the specified position. (Inherited from IList)
OnClearPerforms additional custom processes when clearing the contents of the CollectionBase instance.
OnClearCompletePerforms additional custom processes after clearing the contents of the CollectionBase instance.
OnInsertPerforms additional custom processes before inserting a new element into the CollectionBase instance.
OnInsertCompletePerforms additional custom processes after inserting a new element into the CollectionBase instance.
OnRemovePerforms additional custom processes when removing an element from the CollectionBase instance.
OnRemoveCompletePerforms additional custom processes after removing an element from the CollectionBase instance.
OnSetPerforms additional custom processes before setting a value in the CollectionBase instance.
OnSetCompletePerforms additional custom processes after setting a value in the CollectionBase instance.
OnValidatePerforms additional custom processes when validating a value.
ReferenceEqualsDetermines whether the specified Object instances are the same instance. (Inherited from Object)
RemoveWhen implemented by a class, removes the first occurrence of a specific object from the IList. (Inherited from IList)
RemoveAtRemoves the element at the specified index of the CollectionBase instance.
System.Collections.ICollection.CopyToCopies the elements of the CollectionBase to an Array, starting at a particular Array index.
System.Collections.IList.AddAdds an item to the CollectionBase.
System.Collections.IList.ContainsDetermines whether the CollectionBase contains a specific value.
System.Collections.IList.IndexOfDetermines the index of a specific item in the CollectionBase.
System.Collections.IList.InsertInserts an item into the CollectionBase at the specified position.
System.Collections.IList.RemoveRemoves the first occurrence of a specific object from the CollectionBase.
System.Collections.IList.this[]Gets or sets the element at the specified index.
ToStringReturns a String that represents the current Object. (Inherited from Object)
this[]When implemented by a class, gets or sets an item to the IList. (Inherited from IList)
PropertyDescription
CountGets the number of elements contained in the CollectionBase instance.
InnerListGets an ArrayList containing the list of elements in the CollectionBase instance.
IsFixedSizeWhen implemented by a class, gets a value indicating whether the IList has a fixed size. (Inherited from IList)
IsReadOnlyWhen implemented by a class, gets a value indicating whether the IList is read-only. (Inherited from IList)
IsSynchronizedWhen implemented by a class, gets a value indicating whether access to the ICollection is synchronized. (Inherited from ICollection)
ListGets an IList containing the list of elements in the CollectionBase instance.
SyncRootWhen implemented by a class, gets an object that can be used to synchronize access to the ICollection. (Inherited from ICollection)
System.Collections.ICollection.IsSynchronizedGets a value indicating whether access to the CollectionBase is synchronized.
System.Collections.ICollection.SyncRootGets an object that can be used to synchronize access to the CollectionBase.
System.Collections.IList.IsFixedSizeGets a value indicating whether the CollectionBase has a fixed size.
System.Collections.IList.IsReadOnlyGets a value indicating whether the CollectionBase is read-only.

Inheritance Hierarchy

Object
CollectionBase

Examples

// This examples shows how to implement a CollectionBase.

// It shows also some properties and method of the CollectionBase class.

 

using System;

using System.Collections;

using System.Diagnostics;

 

public class SampleCollectionBase

{

     static void Main()

     {

          // Creates and initializes a new CollectionBase.

          MyCharCollection myCharCol = new MyCharCollection();

 

          // Adds elements to the collection.

          myCharCol.Add( 'a' );

          myCharCol.Add( 'b' );

          myCharCol.Add( 'c' );

          myCharCol.Add( 'd' );

          myCharCol.Add( 'e' );

 

          // Checks some properties of the CollectionBase instance.

          Debug.WriteLine("Properties of the collection:");

 

          bool isfixedS = myCharCol.IsFixedSize;

          Debug.WriteLine("\tFixed size:" +isfixedS.ToString());

 

          bool isSync = myCharCol.IsSynchronised;

          Debug.WriteLine("\tSynchronised:" +isSync.ToString());

 

          // Displays the contents of the collection.

          Debug.WriteLine("\nInitial contents of the collection:");

          DisplayValues(myCharCol);

 

          // Searches the collection with Contains and IndexOf.

          bool contains3 = myCharCol.Contains( 'c' );

          Debug.WriteLine("\t"+@"Contains ""c"":"+contains3);

 

          int i2 =myCharCol.IndexOf( 'd' );

          Debug.WriteLine("\t"+@"Index of ""d"":"+i2.ToString() +"\n");

 

          // Inserts an element into the collection at index 3.

          myCharCol.Insert( 3, 'A');

          Debug.WriteLine("Contents of the collection after inserting at index 3:");

          DisplayValues(myCharCol);

 

          // Gets and sets an element using the index.

          Debug.WriteLine("\tElements at index 2:" +myCharCol[2]);

 

          myCharCol[4] ='C';

          Debug.WriteLine("\n"+@"Contents of the collection after setting the element at index 4 to ""C"":");

          DisplayValues2(myCharCol);

 

          // Removes an element from the collection.

          myCharCol.Remove('a' );

          Debug.WriteLine("\n"+@"Contents of the collection after deleting ""a"":");

          DisplayValues2(myCharCol);

 

          // Creates and initializes a new array of char.

          Array myCharArray = new Char[7] {'t','u','v','w','x','y','z'};

 

          // Displays the content of an array of char.

          Debug.Write("\nContents of the array of string:");

          DisplayArrayValues(myCharArray);

 

          // Copies the elements of the SortedList into the array.

          myCharCol.CopyTo((Char[])myCharArray, 0);

 

          // Display of the content of the array after copying the elements of the SortedList in it.

          Debug.Write("\nContents of the array after copying the elements of the SortedList in it:");

          DisplayArrayValues(myCharArray);

     }

 

     // Displays values using Count and this[].

     static void DisplayValues( MyCharCollection myCharColBase )

     {

          int i=0;

          int count = myCharColBase.Count;

          for(int y=1; y<=count;y++)

          {

              Debug.WriteLine("\t["+(i++)+"]" +myCharColBase[y-1]);

          }

     }

 

     // Displays values using an enumerator.

     static void DisplayValues2( CollectionBase myCharColBase)

     {

          int i=0;

          System.Collections.IEnumerator myEnumerator = myCharColBase.GetEnumerator();

          while ( myEnumerator.MoveNext() )

               Debug.WriteLine("\t["+(i++)+"]" + myEnumerator.Current);

     }

 

     // Displays values of an array.

     public static void DisplayArrayValues ( Array array )

     {

          for ( int i = 0; i < array.Length; i++ )

          {

               Debug.Write(array.GetValue(i)+" ");

          }

     }

}

 

public class MyCharCollection : CollectionBase

{

     public Char this[ int index ]

     {

          get

          {

               return( (Char) List[index] );

          }

          set

          {

               List[index] = value;

          }

     }

 

     public int Add( Char value )

     {

          return( List.Add( value ) );

     }

 

     public int IndexOf( Char value )

     {

          return( List.IndexOf( value ) );

     }

 

     public void Insert( int index, Char value )

     {

          List.Insert( index, value );

     }

 

     public void Remove( Char value )

     {

          List.Remove( value );

     }

 

     public void CopyTo(Array array, int index )

     {

          InnerList.CopyTo(array, index );

     }

 

     public bool Contains( Char value )

     {

          return( List.Contains( value ) );

     }

 

     public bool IsFixedSize

     {

         get

         {

             return( List.IsFixedSize );

         }

     }

 

     public bool IsSynchronised

     {

         get

         {

             return( List.IsSynchronized );

         }

     }

 

     protected override void OnInsert( int index, Object value )

     {

          // Insert additional code to be executed only when inserting values.

     }

 

     protected override void OnRemove( int index, Object value )

     {

          // Insert additional code to be executed only when removing values.

     }

 

     protected override void OnSet( int index, Object oldValue, Object newValue )

     {

          // Insert additional code to be executed only when setting values.

     }

}

 

/*

 

The output of the sample.

 

Properties of the collection:

     Fixed size:False

     Synchronised:False

 

Initial contents of the collection:

     [0]a

     [1]b

     [2]c

     [3]d

     [4]e

Contains "c":True

Index of "d":3

 

Contents of the collection after inserting at index 3:

     [0]a

     [1]b

     [2]c

     [3]A

     [4]d

     [5]e

Elements at index 2:c

 

Contents of the collection after setting the element at index 4 to "C":

     [0]a

     [1]b

     [2]c

     [3]A

     [4]C

     [5]e

 

Contents of the collection after deleting "a":

     [0]b

     [1]c

     [2]A

     [3]C

     [4]e

 

Contents of the array of string:t u v w x y z

Contents of the array after copying the elements of the SortedList in it:b c A C e y z

 

*/

Class Information

NamespaceSystem.Collections
Flash Librarycorlib.scl
Flash Library Version2.0.0.2466
Silverlight LibrarySystem.Windows.Forms.dll



© 2003-2007 NETiKA Technologies. All rights reserved.