手机
当前位置:查字典教程网 >编程开发 >C#教程 >c#测试反射性能示例
c#测试反射性能示例
摘要:Activator.CreateInstance和AssemblyCreateInstance性能测试复制代码代码如下:usingSyste...

Activator.CreateInstance和AssemblyCreateInstance性能测试

复制代码 代码如下:

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);

}

}

【c#测试反射性能示例】相关文章:

C#绝对路径拼接相对路径的实例代码

C#数据库操作小结

如何利用反射构建元数据查看器

C#关于反射加载的问题

C#泛型与非泛型性能比较的实例

C#求解哈夫曼树,实例代码

关于C#基础知识回顾--反射(二)

c#简单读取文本的实例方法

c# n个数排序实现代码

c# 方法可变数量的参数

精品推荐
分类导航