Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

What are the collections and what are various types of collections in .NET?

user-image
Question ajoutée par Muhammed Effat Ahmed Afifi , Project Leader [Microsoft Business Unit] , Wipro Arabia Limited
Date de publication: 2013/04/15
Panneer selvam xavier
par Panneer selvam xavier , Supply Chain Analyst / Trainer , Infonet

These aren't all lists, although they're all collections.
Here's a quick summary.
Non-generic collections (API is in terms of object.
Values types are boxed.
These are mostly in the System.Collections namespace: ArrayList: A list of items, backed by an array.
Fast random read/write access.
Fast add to the tail end, if the buffer doesn't need resizing.
Hashtable: Map from key to value.
Keys are unique, values don't have to be.
Uses the GetHashCode method to achieve near O(1) read/write access (aside from nasty cases where all items have the same hash, or the backing store needs rebuilding).
Iterating over the key/value pairs gives an unpredictable order.
(Well, effectively unpredictable.) SortedList: Like a Hashtable, but the entries are always returned in sorted-by-key order.
Stored as a list of key/value pairs.
Stack: Last-in-first-out collection Queue: First-in-first-out collection Array: Fixed-size O(1) random-access; non-generic, but has strongly typed forms as well Generic collections.
(Strongly-typed API, will not box value types (assuming suitable T).
These are mostly in the System.Collections.Generic namespace: List: Like ArrayList Dictionary: like Hashtable SortedList: like SortedList SortedDictionary: like SortedList, but stored as a tree of key/value pairs which gives better performance in many situations.
See docs for more detail.
LinkedList: Doubly linked list (fast access to head and tail) Stack: Like Stack Queue: Like Queue ReadOnlyCollection: Like List but giving a read-only view Possibly the most important collection interface is IEnumerable (and IEnumerable).
This represents a sequence of items much like a Stream represents a sequence of bytes.
There is no random access, just forward-reading.
LINQ to Objects is based on this, and pretty much all collection types implement it.

More Questions Like This

Avez-vous besoin d'aide pour créer un CV ayant les mots-clés recherchés par les employeurs?