• .net中集合、容器(Collection)的这些事


    一般的开发中常用的集合有:

    列表:List

    集合:Set

    字典:Dictionary

    队列:Queue

    栈:Stack

    只要知道了这些名字,在FCL库中可以找到合适的实现,如下列出了各种类,根据需要选择即可。

    命名空间

    引入的.net版本

    说明

    集合实例

    System.Collections 

    1.0

    普通的集合类、接口等

    ArrayList

    BitArray

    HashTable

    Queue

    SortedList

    Stack

    System.Collections.Specialized

    1.0

    特定的强类型集合

    HybridDictionary

    ListDictionary

    NameValueCollection

    OrderedDictionary

    StringCollection

    StringDictionary

    1.0的集合类仅在兼容以前代码时使用,现在一般使用如下的类

    System.Collections.Generic

    2.0

    泛型的集合

    更好的类型安全和性能

    Dictionay<T,V>

    HashSet<T>

    LinkedList<T>

    List<T>

    Queue<T>

    SortedDictionary<T,V>

    SortedSet<T>

    Statck<T>

    3.0

    线程安全容器

     

    SynchronizedCollection<T>

    SynchronizedKeyedCollection<K, T >

    SynchronizedReadOnlyCollection< T >

    System.Collections.ObjectModel

    2.0

    用于属性和方法返回类型

    可重用库设计时使用

    Collection<T>

    KeyedCollection<T,V>

    ObervableCollection<T>

    ReadOnlyCollection<T>

    ReadOnlyObervableCollection<T>

    System.Collections.Concurrent

     

    4.0

    线程安全集合

    处理了线程的并发访问

    非阻塞[如果一个线程试图提取一个不存在的元素,线程立即返回]

    ConcurrentBag<T>

    ConcurrenDictionary<T,V>

    ConcurrenQueue<T>

    ConcurrenStack<T>

    ConcurrenDictionary的枚举GetEnumerator不返回快照,其他返回快照

     

    阻塞集合

    BlockingCollection<(T>

    Wintellect’s Power Collections

    Wintellect提供了类似STL的集合和算法类

    集合类

     

    BigList<T>

    有序T的结合,操作100个以上的数据项效率高

    Bag<T>

    无序T的集合,集合进行了哈希处理,允许重复项

    OrderedBag<T>

    有序T的集合,允许重复项

    Set<T>

    无序T的集合,不允许重复项

    OrderedSet<T>

    有序T的集合,不允许重复项

    Deque<T>

    双端队列

    OrderedDictionary<T,V>

    字典,键进行了排序

    MultiDictionary<T,V>

    字典,每个键有多个值,允许重复键,数据项无序

    Ordered MultiDictionary<T,V>

    字典,每个键有多个值(值也进行了排序),允许重复键,键进行了排序

     

     

    Algorithms

    针对泛型集合的查找、替换、排序、转换、组合等各种算法的实现类

     

    [优先使用集合类自带的算法函数,只有在没有需要的函数时才使用这些通用的算法和STL的道理一样]

  • 相关阅读:
    RAISERROR (Transact-SQL)的用法
    Eclipse 工程中set() get()等方法报错的解决方法
    SqlServer单步调试
    centOS7 查看防火墙状态
    如何查看Linux端口占用情况
    异常处理机制(Begin try Begin Catch)
    inner join 、left join 、right join 和full join的区别
    Emacs 快速指南
    x01.DiamondIDE: hello ide
    剑指offer大总结
  • 原文地址:https://www.cnblogs.com/2018/p/2035531.html
Copyright © 2020-2023  润新知