zoukankan      html  css  js  c++  java
  • 关于反射中创建类型实例的两种方法

    第一种从构造函数创建对象

    object o = null;
    System.Type t 
    = System.Type.GetType(this.Type);
    constructor 
    = t.GetConstructor(new Type[0]);  //t.GetConstructor(Type.EmptyTypes)也可以

      o 
    = constructor.Invoke(null);

    第二种反射的静态方法
    object o = null;
    System.Type t 
    = System.Type.GetType(this.Type);
    = System.Activator.CreateInstance(t,true);

    Activator 是包含特定的方法,用以在本地或从远程创建对象类型,或获取对现有远程对象的引用。

    这两种方法有什么区别呢?
  • 相关阅读:
    css 面试学习
    关于CSS的图像放大问题的解决,需要借助jQuery等直接用css3设置
    DEBUG使用
    crontab
    od
    dumpe2fs
    mke2fs
    dd
    GDB
    rm
  • 原文地址:https://www.cnblogs.com/king_astar/p/217037.html
Copyright © 2011-2022 走看看