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]]);
    }

  • 相关阅读:
    [HNOI2004]L语言
    [TJOI2018]异或
    如何定位低效SQL?
    索引失效的情况有哪些?
    trace的作用?
    show profile的作用?
    索引的使用原则
    MySQL主从复制的步骤
    什么是聚簇索引
    什么是全文索引?
  • 原文地址:https://www.cnblogs.com/qfcndtt/p/2674908.html
Copyright © 2011-2022 走看看