• 基本类型泛型(一)



        public static class Program {
            
    public static void Main() {
                ValueTypeTest();
                ReferenceTypeTest();
                Console.ReadLine();
            }

            
    private static void ValueTypeTest() {
                
    const Int32 count = 10000000;
                
    using (new OperatorTimer("泛型值类型:List<Int32>")) {
                    List
    <Int32> l = new List<int>();
                    
    for (int i = 0; i < count; i++{
                        l.Add(i);
                        Int32 x 
    = l[i];
                    }

                    l 
    = null;
                }

                
    using (new OperatorTimer("非泛型值类型:ArrayList of Int32")) {
                    ArrayList a 
    = new ArrayList();
                    
    for (int i = 0; i < count; i++{
                        a.Add(i);
                        Int32 x 
    = (Int32)a[i];
                    }

                    a 
    = null;
                }

            }

            
    private static void ReferenceTypeTest() {
                
    const Int32 count = 10000000;
                
    using (new OperatorTimer("泛型类型引用类型:List<String>")) {
                    List
    <String> l = new List<string>();
                    
    for (int i = 0; i < count; i++{
                        l.Add(
    "X");
                        String x 
    = l[i];
                    }

                    l 
    = null;
                }

                
    using (new OperatorTimer("非泛型类型引用类型:ArrayList of String")) {
                    ArrayList a 
    = new ArrayList();
                    
    for (int i = 0; i < count; i++{
                        a.Add(
    "X");
                        String x 
    = (String)a[i];
                    }

                    a 
    = null;
                }

            }

        }

        
    internal sealed class OperatorTimer : IDisposable {
            
    private Int64 m_starttime;
            
    private String m_text;
            
    private Int32 m_collectionCount;
            
    public OperatorTimer(String t) {
                PrepareForOperation();
                m_text 
    = t;
                m_collectionCount 
    = GC.CollectionCount(0);
                m_starttime 
    = Stopwatch.GetTimestamp();
            }

            
    public void Dispose() {
                Console.WriteLine(
    "{0,6:###.00} seconds (GCs={1,3}){2}",
                    (Stopwatch.GetTimestamp() 
    - m_starttime) / (Double)Stopwatch.Frequency,
                    GC.CollectionCount(
    0- m_collectionCount,
                    m_text);
            }

            
    public static void PrepareForOperation() {
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
            }

        
        }
    161FCL中的泛型

    162WintellectPower Collections
     为了使CLR编程人员也能使用C++标准模板库的部分集合类,Wintellect制作了Power Collections库。可从Wintellect.com下载。
    163泛型基础结构
  • 相关阅读:
    Linux常用命令,touch命令,vi和vim命令,文件查看命令,文本处理命令,备份压缩命令,网络与磁盘命令,软件安装命令
    Linux命令整理,用户管理命令,用户组管理命令,系统管理命令,目录管理常用命令
    单元测试基本步骤?单元测试三个常用注解?日志体系结构和log4j,Log4j三个核心?
    cookies,sessionStorage 和 localStorage 之间有什么区别?
    filter() 、find()、findIndex()
    设置多行文本隐藏显示省略号时样式丢失了
    react 中封装一个简单的滚动条组件
    react-router-cache-router
    浅谈React 中 Component与PureComponent如何使用
    React.Fragment
  • 原文地址:https://www.cnblogs.com/tenghoo/p/1209921.html
Copyright © 2020-2023  润新知