zoukankan      html  css  js  c++  java
  • 泛型方法

    在开发CS插件时,使用了泛型集合Dictionary和List,但是时常要调用Components中的一些方法要传入ArrayList集合,但暂时不想修改核心组件,所以需要把泛型转为非泛型,使用泛型方法是一个比较好的方法。

            public static ArrayList GenericToArrayList<T>(List<T> list)
            
    {
                ArrayList alist 
    = new ArrayList();

                
    foreach (T t in list)
                
    {
                    alist.Add(t);
                }


                
    return alist;
            }

            public static Hashtable GenericToHashtable<TKey, TValue>(Dictionary<TKey, TValue> dic)
            
    {
                Hashtable ht 
    = new Hashtable();

                Dictionary
    <TKey, TValue>.Enumerator enumerator = dic.GetEnumerator();
                
    while (enumerator.MoveNext())
                
    {
                    ht.Add(enumerator.Current.Key, enumerator.Current.Value);
                }


                
    return ht;
            }

    附:在VS2005中设置跟踪活动项。
    选项-->项目和解决方案-->在解决方案资源管理器中跟踪活动项
  • 相关阅读:
    javascript 事件冒泡
    Java 理论与实践: 正确使用 Volatile 变量
    Concurrency,Java 并发
    POJ2379 ACM Rank Table 模拟题
    HDU1711Number Sequence KMP
    POJ1061 青蛙的约会 扩展GCD
    HDU2523 SORT AGAIN HASH
    HDU2087剪花布条 KMP
    HDU3736 Cyclic Nacklace KMP
    HDU1709The Balance 母函数
  • 原文地址:https://www.cnblogs.com/chenjunbiao/p/1760252.html
Copyright © 2011-2022 走看看