C#笔记-反射

2017-10-19  本文已影响39人  AiDede

我们平常调用一个类库的方式,通常为添加引用的方式

namespace Reflection
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("");
            //Code
            Console.ReadLine();
        }
    }
}
namespace DBUtil
{
    public class SqlHelper
    {
        public SqlHelper() {
            Console.WriteLine("这里是SqlHelper的构造方法");
        }
        public void Query() {
            Console.WriteLine("SqlHelper的查询方法");
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DBUtil;//添加命名空间
namespace Reflection
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("");

            SqlHelper oSqlHelper = new SqlHelper();
            oSqlHelper.Query();

            Console.ReadLine();
        }
    }
}
运行结果

通过反射可以动态的调用我们的DLL

using System.Reflection;
            Assembly assembly = Assembly.Load("DBUtil");//动态加载Dll
上一篇下一篇

猜你喜欢

热点阅读