我如何创建一个字符串,它提供的类名的实例?字符串、创建一个、实例

2023-09-03 08:03:08 作者:吧嗒吧嗒

我有写与类名作为参数的功能,这是字符串的函数。所以,我需要创建这个类名称实例。

  createInstance建立(串类名){
  .............
  //这里我需要创建类名的情况下,
  .............

 }
 

解决方案

  Activator.CreateInstance(Type.GetType(类名));
 

C 如何在一个文件夹下创建按时间生成的子文件夹

I have to write a function with class Name as Parameter to function, which is in string. So that i need to create instance of this class name.

createInstance(string ClassName){
  .............
  //Here i Need to create instance of  ClassName,
  .............

 }

解决方案

Activator.CreateInstance(Type.GetType(ClassName));