".NET performance optimization" - a collection of Chapter V

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/zhonghua_csdn/article/details/90709041

Collections

Avoid using System.Collections type namespace. We recommend the use of a set of generic versions and concurrent versions, since they are the type of security is very high, and also through other improvements.

System.Collections.Generic namespace contains interfaces and classes that define a generic collection, the user can use to create a set of generic strongly typed collections, which provides a set of type safety and performance than non-generic strongly typed collections better.

set description
ArrayList,List<T> List, List <T> is a generic form of ArrayList.
Stack<T> Stack
Queue<T> queue
HashSet<T>,SortedSet<T> Set, comprising a set of elements will not be repeated a "set (SET)" where, HashSet <T> unordered list comprising a set of elements will not be repeated;. SortedSet <T> set comprising an ordered list of elements is not repeated.
LinkedList<T> Doubly linked list
Dictionary<TKey, TValue> Dictionary, in accordance with a key to allow access elements. Dictionary also called mapping or hash table. The main feature of the dictionary is the ability to quickly find value in accordance with the key. Also free to add and remove elements, a bit of List <T> class, but did not move the performance overhead of subsequent elements in memory.
SortedDictionary<TKey, TValue> Ordered dictionary, is a binary search tree, which is sorted according to key elements. The key type must implement IComparable <TKey> interface.
SortedList<TKey, TValue> Ordered list, sorted by key class to the element.

Thread-safe collection

The following table lists System.Collections.Concurrent set type namespace.

Types of Explanation
BlockingCollection<T> To achieve IProducerConsumerCollection <T> provide restrictions and blocking of all types. For more information, see BlockingCollection overview .
ConcurrentDictionary<TKey,TValue> Key to achieve thread-safe dictionary.
ConcurrentQueue<T> FIFO (First In First Out) queue of thread-safe.
ConcurrentStack<T> Thread safety realization LIFO (last in, first out) stack.
ConcurrentBag<T> Thread unordered collection of elements of the security implementation.
IProducerConsumerCollection<T> Type must implement in order to BlockingCollectioninterface to use.

Guess you like

Origin blog.csdn.net/zhonghua_csdn/article/details/90709041