zoukankan      html  css  js  c++  java
  • C# 简单的反射机制实例

    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方法");
            }
    
        }
    
    }
  • 相关阅读:
    POJ 2407 Relatives 欧拉函数
    HDU 4704 Sum 超大数幂取模
    HDU 4699 Editor 维护栈
    HDU 4696 Answers 水题
    HDU 4686 Arc of Dream 矩阵
    [转]高斯消元题集
    [转]计算几何题集
    POJ 2981 Strange Way to Express Integers 模线性方程组
    Linux 设置文件默认打开方式
    FZU 1402 猪的安家 中国剩余定理
  • 原文地址:https://www.cnblogs.com/zoro-zero/p/4064516.html
Copyright © 2011-2022 走看看