c# typeof 与 Type.GetType 使用与效率对比

        static void ReflectionTest()
        {//测试两种反射的效率问题
            //Type.GetType()只能在同一个程序集中使用,typeof则可以跨程序集(assembly)
            //通过下面的实测,发现typeof是比GetType快40多倍
            var timer = Stopwatch.StartNew();
            timer.Start();

            Type tx = Type.GetType("string");
            var tx1 = Type.GetType("float");
            timer.Stop();

            Console.WriteLine("T1= " + timer.Elapsed);//0.0000471

            timer.Restart();

            tx = typeof(string);
            tx1 = typeof(float);

            timer.Stop();
            Console.WriteLine("T2= " + timer.Elapsed);//0.0000011
        }
原文地址:https://www.cnblogs.com/timeObjserver/p/8473456.html