码迷,mamicode.com
首页 > Windows程序 > 详细

C# 简单的反射机制实例

时间:2014-10-31 11:35:44      阅读:226      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   color   ar   sp   div   on   log   

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Collections;
using ConsoleApplication1;
using ConsoleApplication2;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
          

            string namespaceName1 = "ConsoleApplication1";

            ConAppPerson1 p1 = Assembly.Load(namespaceName1).CreateInstance(namespaceName1 + ".ConAppPerson1") as ConAppPerson1;

            p1.SayHello();


            string namespaceName2 = "ConsoleApplication2";

            ConAppPerson2 p2 = Assembly.Load(namespaceName2).CreateInstance(namespaceName2 + ".ConAppPerson2") as ConAppPerson2;

            p2.SayHello();


            Console.ReadKey();


        }

    }

}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    public class ConAppPerson1
    {
        public string Name { get;set;}

        public int Age { get; set; }

        public void SayHello() {
            Console.WriteLine("ConsoleApplication111111 SayHello方法");
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
    public class ConAppPerson2
    {
        public string Name { get; set; }

        public int Age { get; set; }

        public void SayHello()
        {
            Console.WriteLine("ConsoleApplication2222222 SayHello方法");
        }

    }

}

 

C# 简单的反射机制实例

标签:style   blog   io   color   ar   sp   div   on   log   

原文地址:http://www.cnblogs.com/zoro-zero/p/4064516.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!