How to create an object instance of class with internal constructor via reflection?

前端 未结 2 1653
陌清茗
陌清茗 2021-01-18 11:17

Example:

class Program
{
    static void Main(string[] args)
    {
        var myClass = Activator.CreateInstance(typeof(MyClass));
    }
}
         


        
2条回答
  •  梦毁少年i
    2021-01-18 11:51

    It is not that impossible. you've to tell it is not a public.

    var myClass = Activator.CreateInstance(typeof(MyClass), true);//say nonpublic
    

提交回复
热议问题