C # Advanced Programming 47-day----collection interfaces and types

Source: Internet
Author: User

Collection Interfaces and types

The interfaces implemented by arrays and array classes are described earlier . The size of the array is fixed . if the number of elements is dynamic , should be a private collection class .

List<t> is a collection class that is equivalent to an array . There are other types of collections : Queue , Stack , linked lists and dictionaries .

Most collection classes can be found in the system.collections and System.Collections.Generic namespaces . The generic collection class is located in the System.Collections.Generic in the name space ; a collection class that is dedicated to a specific type is located in System.Collections.Specialized in the name space . Thread-Safe collection classes are located in the System.Collections.Concurrent in the name space .

The interfaces for collection and list implementations are as follows :

Interface

Description

Ienumerable<t>

If the foreach statement is used for a collection, the IEnumerable interface is required . This excuse defines the method GetEnumerator (), he returned to a realization of the IEnumerator enumeration of Interfaces

Icollection<t>

Icollection<t> interface has a generic collection class that implements Use this excuse to get the number of elements in the collection (Count properties ", Copy the collection into the array (CopyTo () method You can also add and remove elements from the collection (Add (), Remove (), Clear ())

List<t>

Ilist<t> Interface for the list of elements that can be accessed through a location This interface defines a   indexer &NBSP can be inserted or deleted at the specified location in the collection; mount some items (Insert () and remove () method ). Ilist<t> interface derived from Icollection<t> interface

Iset<t>

Iset<t> The interface is implements the set of this interface allows merging of different sets Get the intersection of two sets check if two collections overlap interface derived from Icollection<t> interface

Idictionary<tkey,tvalue>

the Idictionary<tkey,tvalue> interface is implemented by a generic collection class that contains keys and values . all keys and values can be accessed using this interface. , indexers that use key types can access certain items , you can also add or remove certain items

Ilookup<tkey,tvalue>

The ilookup<tkey,tvalue> interface is similar to the idictionary<tkey,tvalue> interface , A collection that implements the interface has keys and values , and can contain multiple values through a key

Icomparer<t>

Interface ICOMMPARER<T> through comparer ()

Iequalitycomparer<t>

Interface IEQUALITYCOMPARER<T> implemented by a comparator , This comparator can be used for keys in dictionaries Use this interface You can compare objects for equality .net This interface is also implemented by arrays and tuples

Iproducerconsumercolllection<t>

the Iproducerconsumercollection<t> interface is . added in NET4 , It supports new thread-Safe collection classes

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

C # Advanced Programming 47-day----collection interfaces and types

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.