zoukankan      html  css  js  c++  java
  • 泛型集合(.NET 2.0)

    1、List<T>

      来判断是否为空:count属性;

      判断某个元素是否在该List中:List. Contains(T item);

      遍历可使用:foreach、for;

      List清空:List. Clear () ;

    2、Dictionary<T1,T2>

      来判断是否为空:count属性;

      遍历可使用:

    //KeyValuePair<T,K>
    foreach (KeyValuePair<string, int> kv in list)
    {
      Console.WriteLine(kv.Key + kv.Value);
    } 
    //3.0以上版本
    foreach (var item in list) 
    {
      Console.WriteLine(item.Key + item.Value);
    } 
     //过键的集合取
    foreach (string key in list.Keys)
    {
      Console.WriteLine(key + list[key]);
    } 
     //直接取值
    foreach (int val in list.Values) 
    { 
      Console.WriteLine(val);
    } 
    //非要采用for的方法也可
    List<string> test = new List<string>(list.Keys);
    for (int i = 0; i < list.Count; i++)
    { 
      Console.WriteLine(test[i] + list[test[i]]);
    }

  • 相关阅读:
    python常用模块②
    python常用模块①
    面向对象相关部分双下划线方法补充
    面向对象进阶 上
    面向对象初识④
    面向对象初识③
    综合架构-负载均衡
    wecent 搭建
    综合架构--存储
    综合架构--备份
  • 原文地址:https://www.cnblogs.com/qfcndtt/p/2674908.html
Copyright © 2011-2022 走看看