Article 06th: C # collection classes of important components

Source: Internet
Author: User

 

Out of Technology

Su Shi's "shichibi Fu": there is no wine, there is no wine, there is no wine; moon Bai Feng Qing, so good night what? The technicians appreciate the ancient poems while doing the technology. Haha, this is some gossip.

 

Preface

To save a set of data in C, an array or a linked list is usually used for storage. In C #, we don't need to worry so much, because C # provides some practical collection classes that allow you to easily manage one or more groups of memory objects. These collections include ArrayList, HashTable, and List <T>.

 

ArrayListClass

In MSDN, there is only one introduction to ArrayList: The IList interface is implemented using arrays that can be dynamically increased by size as needed. We recommend that you use ArrayList because dynamic arrays are not supported in C #. You can use ArrayList to implement dynamic arrays.

Common Operations on ArrayList include Add, Insert, Remove, and IndexOf. You can use these methods to perform most operations. For more information about these operations, see the description in MSDN.

 

HashtableClass

Description in MSDN: a set of key/value pairs. These key/value pairs are organized according to the hash code of the key.

Some friends may have manually implemented the Hashtable function. Hash Algorithms in C language are very important. Unfortunately, I did not learn well. What I learned can only cope with the teacher's homework. Fortunately, the Hashtable class is provided in C # to implement the key/value pair operation function.

The operation of Hashtable is simpler. The Add method is used to Add a key/value pair, and the value can be directly accessed through the key. That is to say, if a dt Hashtable object is defined, you can use dt [key] to obtain the Value of an Object. If the key Value does not exist, a null Value is returned.

These operations are convenient and easy to use. For more information, see and in MSDN.

 

List <T>Class

Description in MSDN: A list of strong types of objects that can be accessed through indexes. Provides methods for searching, sorting, and operating the list.

The strongly typed table is called generic. What is generic? This is enough to discuss the previous pages. I just want to explain that "generic" means that "T" can be any other type, but it must be a fixed type. After this type is determined, the List <T> object can only be a T-class instance. This is my understanding of generic usage. If you want to know the positive solution, you can refer to it.

List <T> the usage is nothing special. C # provides a wide range of operations for it. You can refer to and understand it in MSDN.

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.