zoukankan      html  css  js  c++  java
  • 基本类型泛型(一)


        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泛型基础结构
  • 相关阅读:
    JDBC事务管理
    JDBC常见操作
    Java集合之List接口
    Nginx+Keepalived+Lvs实现双机热备
    Nginx+Consul+Upsync实现动态负载均衡
    DNS域名解析概念
    WPF中实现两个窗口之间传值
    C# 重写(override)和覆盖(new)
    C# DateTime.Now函数
    WPF中在后台实现控件样式
  • 原文地址:https://www.cnblogs.com/tenghoo/p/1209921.html
Copyright © 2011-2022 走看看