Asp. NET Beginner: Understanding the collection of. Net

Source: Internet
Author: User
Asp.net| Beginners | collection

. NET a large number of collection objects will cause some confusion, this "guide" guide will help you find your direction in the System.Collections domain.

Collections provide a way to format any object in storage, and we all know how helpful it is in everyday program design. NET class Library provides a series of confusing collection objects, and each object has a special purpose, which seems to hinder our use of these "wealth", in fact, more choices means more flexibility, but also means more complex. Therefore, it should be your concern that you should have a good understanding of the circumstances in which you use that type of collection, and follow me to learn how to use it. NET of the collection.

. NET definition of a collection </p><p ><center></center></p><p >

From a. NET perspective, a collection can be defined as one or more System.Collections.ICollection, System.Collections.IDictionary and System.Collections.IList interface objects, according to this definition, I will divide the set of "constructs" within the scope of System.Collections domain space into three categories:

Ordered set: Only a collection of ICollection interfaces is implemented, in fact the order of insertions determines the order in which objects are retrieved from the collection. The System.Collections.Stack class and the System.Collections.Queue are examples of two ICollection sets.

Index collection: Implements a collection of IList interfaces that can be retrieved from a zero-based numeric index, just like an array. The System.Collections.ArrayList object is an example of an indexed collection.

Set of key values: Implements a collection of IDictionary interfaces that contain items that can be retrieved by some associated key values, and the content of IDictionary is usually sorted in some form based on the key value, which can be represented as a sorted enumeration when retrieved. The System.Collections.HashTable class implements the IDictionary interface.

As you can see, the function of a given set is controlled by a particular interface or the interface it implements, and if you don't have a lot of contact with the object program in the opposite direction, this seems to be confusing, if not meaningless. However, you should know that the function of creating an object in this way not only gives a similar set of methods to a similar object, but also allows them to be treated as essentially the same class when necessary, which is called Polymorphism in object-oriented programming.

System.Collections Guide to the "guide"

There are 6 built-in common collections in the System.Collections name domain, you can use them in a program, and a few special sets can be found in System.Collections.Specialized, and you'll find them useful in some situations. With a few exceptions, each particular set has a similar function to a built-in set, let's look at these built-in collections and some of the less esoteric special collections.

Stacks and queues

The System.Collections.Stack and System.Collections.Queue classes are classes that implement only the ICollection interface, which arranges items of the System.Object type into the collection in the order in which they are added, and the objects in the collection are only in the following order Get to: The stack is LIFO, and the queue is FIFO, and usually you will consider using these collections in the following situations:

The order in which items are received and processed is important;

You can delete a project after processing it;

You do not need to access any item in the collection;

Array table

The System.Collections.ArrayList class is a class that implements only the IList interface, and the mixture of the array and the collection is the best description, the array table arranges the items in the order in which they were added, each item is assigned an index identifier, which can be retrieved in any order according to the relevant index number, and the array table will Increased and larger, which makes it more flexible than a generic array, however, all items that can be converted to System.Object can be accepted by the array table, so it is much more expensive than the traditional array system overhead, and it is not strongly typed (strongly typed).



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.