c#根据一个传入的字符串得到需要使用的类
Type yourType =
Type.GetType("System.Web.UI.WebControls.Label");
Object yourLabel = Activator.CreateInstance(yourType);
本文介绍如何在C#中通过传入的字符串类型名称来动态获取对应的类,并实例化该类。具体实现方式为使用Type.GetType方法获取类型,再通过Activator.CreateInstance方法创建实例。
c#根据一个传入的字符串得到需要使用的类
Type yourType =
Type.GetType("System.Web.UI.WebControls.Label");
Object yourLabel = Activator.CreateInstance(yourType);
1836

被折叠的 条评论
为什么被折叠?