C # Tutorial C # collection (Collection)

Source: Internet
Author: User

C # collection (Collection)

Collection (Collection) classes are classes that are designed for data storage and retrieval. These classes provide support for stacks (stack), queues, lists (list), and hash tables (hash table). Most collection classes implement the same interface.

Collection (Collection) classes serve different purposes, such as dynamically allocating memory for elements, accessing list items based on indexes, and so on. These classes create a collection of objects of the object class. In C #, the Object class is the base class for all data types.

The various collection classes and their usage

The following are the classes of various commonly used system.collection namespaces. Click on the link below to see the details.

Class

Description and Usage

A dynamic array (ArrayList) that represents an ordered collection of objects that can be individually indexed.

It can basically replace an array. However, unlike arrays, you can use an index to add and remove items at a specified location, and the dynamic array will automatically resize it. It also allows dynamic memory allocations, additions, searches, and sorting of items in a list.

Hash table (Hashtable) It uses keys to access the elements in the collection.

When you use keys to access elements, a hash table is used, and you can identify a useful key value. Each item in the hash table has a key/value pair. Key to access the items in the collection.

Column list (SortedList) it can use keys and indexes to access items in the list.

A sorted list is a combination of arrays and hash tables. It contains a list of items that can be accessed using keys or indexes. If you use an index to access the items, it is a dynamic array (ArrayList), and if you use keys to access the items, it is a hash table (Hashtable). Items in the collection are always sorted by key values.

Stack it represents a last-in-first-out collection of objects.

The stack is used when you need to make last-in, first-out access to each item. When you add an item to the list, called the push element, the popup element is called when you remove an item from the list.

Queue it represents a first-in-a-line collection of objects.

Queues are used when you need to make FIFO access to each item. When you add an item to the list, called the queue, when you remove an item from the list, it is called the queue.

Dot Matrix (BitArray) it represents a binary array that uses the value 1 and the.

Bitmap columns are used when you need to store bits, but do not know the number of bits beforehand. You can use an integer index to access items from a lattice column collection, starting with the zero-based index.

This is the "C # tutorial" C # Collection (Collection) content, more relevant content please follow topic.alibabacloud.com (www.php.cn)!

  • 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.