zoukankan      html  css  js  c++  java
  • C#中的Collection 2

    Core Generic interface

        

     

    IEnumerable<T>:you can interate my elemnts, no need to know the count, can not modify my contents (Array在这里)

    var myString = new string[] {"1","2","3","4"}; //可以迭代但是不可以修改Collection本身但是item的值可以修改

    ICollection<T>:I know how many elements I have, and you can modify my contents, but I don't know what kind of collection (不经常用)

    int ICollection<T>.Count

    IList<T> (List在这里)

    var myStringList = new List<string> {"1","2","3","4"}; //可以迭代可以修改Collection本身

    IDictionary<TKey, TValue> (Dictionary在这里)

    ISet<T> (Set在这里)

    IEnumerable<T>

    IEnumerable<T>类型可以迭代,具体实现要用Enumerator,但是foreach已经为我们做好了转换,而且foreach可以作用与所有的collection.

    ICollection<T>

    比IEnumberable<T>多了写

    Count只有ICollection有,Array没有Count property,但是有Array.Length,如果非要数Count就用Linq的IEnumerable<T>.Count()方法。

    对于ICollection Linq有ICollection<T>.Count

    IList<T>

    因为继承自IEnumerable<T>所以有this[index]和indexof(),并且增加了Insert(), 和RemoveAt()

    //look up element
    string saturday = dayOfWeek[5];
    
    //replace element
    dayOfWeek[5] = "SlaveDay";

    IDictionary<TKey, TValue>

    You can look up my element with a Key

    Country country =  countries["UK"];

     

     

  • 相关阅读:
    [剑指Offer] 从尾到头打印链表
    [剑指Offer] 替换空格
    [剑指Offer] 二维数组中的查找
    [LeetCode] 53. Maximum Subarray
    [LeetCode] 283. Move Zeroes
    haproxy + rabbitmq + keepalived的高可用环境搭建
    iis7下站点日志默认位置
    在vs2012中配置使用iisexpress
    tomcat配置域名,单项目指定多域名
    httpget和post
  • 原文地址:https://www.cnblogs.com/shawnzxx/p/3682091.html
Copyright © 2011-2022 走看看