类的反射 typeof 或GetType

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
namespace ConsoleApplication10
{
    class Program
    {
        static void Main(string[] args)
        {
            // 类的反射  typeof 或GetType


            Type tp = typeof(person);
            person  p2 = new person();
          Type   tp1 =  p2.GetType();
            object op = Activator.CreateInstance(tp);
            MethodInfo m1 = tp.GetMethod("show");
            m1.Invoke(op, new object[] { "nishi" });// 通过Invoke 
            person p1 = op as person; //转换调用
            p1.show("asdf");
            Console.ReadKey();
        }
    }

    class person
    {


        public void show(string a)
        {

            Console.WriteLine("哈哈哈哈" + a);
        }

    }
}

  

原文地址:https://www.cnblogs.com/xh0626/p/5096965.html