源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

c#测试反射性能示例

  • 时间:2020-03-07 04:42 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:c#测试反射性能示例
Activator.CreateInstance和AssemblyCreateInstance性能测试
[u]复制代码[/u] 代码如下:
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Security.Cryptography; using System.Text; using HelloWorld.ServiceReference1; using System.Globalization; using System.Reflection; using Interface; namespace HelloWorld {     class Program     {         static void Main(string[] args)         {             Stopwatch s = new Stopwatch();             Assembly a = Assembly.GetExecutingAssembly();             //foreach (var st in a.GetExportedTypes())             //{             //    Console.WriteLine(st.Name);             //}             s.Reset();             s.Start();             Type t = a.GetType("HelloWorld.Test1");             Interface1 i2 = (Interface1)(Activator.CreateInstance(t));             Console.WriteLine((i2.Add(1, 2)));             s.Stop();             Console.WriteLine(s.Elapsed);             s.Reset();             s.Start();             Interface1 i = (Interface1)a.CreateInstance("HelloWorld.Test1");             Console.WriteLine((i.Add(1, 2)));             s.Stop();             Console.WriteLine(s.Elapsed);         }     }     public class Test1 : Interface1     {         public int Add(int a, int b)         {             return a + b;         }     }     public interface Interface1     {         int Add(int a, int b);     } }
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部