A summary of C # non-norm collection classes

Source: Internet
Author: User

Under the mscorlib assembly System.Collections
     Public Interface ICollection: IEnumerable
public interfaceIComparer
public interfaceIDictionary: ICollection, IEnumerable
public interfaceIDictionaryEnumerator: Ienumerato
Public Interface IEnumerable
Public Interface IEnumerator
Public Interface IEqualityComparer
Public interface IHashCodeProvider
Public interface IList : ICollection, IEnumerable
Internal class keyvaluepairs
     IEnumerator   //enumeration Interface     {        MoveNext();         Current {get;}        Reset ();     }

There are two methods in the interface of this method, namely moving to the next item, and resetting the initial one. and an attribute, the return value of this property is a weakly typed object that indicates that the move is unidirectional, can only be moved in one direction, and cannot be selected by its own moving direction and entry

This is the basic method that the collection class must implement.

      PublicinterfaceIEnumerable  //Returns enumeration interface     {                getenumerator();     }

The other interfaces are formed on the basis of these two interfaces.

  public  interface   ICollection : IEnumerable//Ordered collection {//Methods  void  copyto< /strong> (array array, int index); Copy the Collection Object //Properties  int  Count  {get ;  }//the number of elements in the collection bool  issynchronized  {get ;}      Returns whether the collection is multithreaded for simultaneous access to object  SyncRoot  {get ;} Returns the synchronization object} 
public interface IList : ICollection, IEnumerable//index collection
   {    //Methods    Add(object value);    Clear ();    Contains (object value);    IndexOf (object value);    Insert (int index, object value);    Remove (object value);    RemoveAt (int index);    //Properties    isfixedsize get; }    isreadonlyget;}     This Get set; }   }

This interface is very rich, there are some ways to add members, delete members, and so on.
 public  interface   IDictionary : ICollection, IEnumerable//dictionary collection or key-value collection {//Methods  Void    Strong>add  (Object key, object value);    void  Clear  ();    BOOL  Contains  (object key);    IDictionaryEnumerator  GetEnumerator  ();    void  Remove  (object key); //Properties  bool  isfixedsize  { get ;    } bool  isreadonly  {get ;} Object  This  [object key] {get ; set ;    } ICollection  Keys  {get ;} ICollection  Values  {get ;} 

The collection type implements the IEnumerable interface so that the foreach iteration can be used.

A collection class that implements the Icollectoin interface indicates that the elements in the collection are sequential.

The IList interface inherits the ICollection interface, and the collection class that implements the IList interface does not only indicate that the elements in the collection are sequential, but also that the collection class can access the collection elements in a way that is accessed by the subscript and that the subscript is an integer.

The IDictionary interface also inherits the ICollection interface, which implements the Idicionary interface of the collection class to access the collection elements through the access method accessed by the subscript key.

The ICollection interface is the base interface for classes in the System.Collections namespace.

          icollection  interface extension  IEnumerable;IDictionary  and  IList  is the more dedicated interface for extending  icollection . idictionary Implementation is a collection of key/value pairs, like the hashtable class." The > idictionary  implementation is a collection of key/value pairs, such as the hashtable  class. ilist Implementation is a collection of values and their members can be accessed by index, like the arraylist class. " > ilist  implementation             is a collection of values whose members can be accessed through an index, such as the  ArrayList  class.

queue class and the stack class, directly implement the icollection interface." >          Certain collections, such as  Queue  classes and  Stack  classes, restrict access to their elements, directly implementing  icollection  interface.

If both the IDictionary interface and the IList interface do not meet the requirements of the required collection, derive the new collection class from the ICollection interface for increased flexibility









On the basis of this IList interface there are some types that we can use in our actual programming, such as
  1:publicabstractclassArray : ICloneable, IList, ICollection, IEnumerable// The class of the array class is abstract
What we usually use, such as int[] intarray= new int[]{}, is derived from this extraction class.
However, the array is implicitly derived from array, which is done by the compiler, so we do not see the specific implementation process.

Array array1;
Int[] A = new int[] {};
String[] B = new string[] {};
Array1 = A;
Array1 = b

2: Since the size of the array is fixed, and the type is fixed, a ArrayList is invented, which is a variable-length object array

    PublicclassArrayList : IList, ICollection, IEnumerable, ICloneable
Object can be passed into any type, but the performance of the operation involving boxing and unpacking is affected.
3:stack and queue stacks and queues are ordered collections.

The Hashtable implements the IDictionary interface. is a collection of key-value pairs
Both the key and the value are object
These are the non-generic collection classes.






   




A summary of C # non-norm collection classes

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.