Class.forName() 在 .NET 中等效吗? [英] Class.forName() equivalent in .NET?

查看:45
本文介绍了Class.forName() 在 .NET 中等效吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

动态获取对象类型然后创建它的新实例的 C# 方法是什么?

What is the C# way for dynamically getting the type of object and then creating new instances of it?

例如我如何完成以下 Java 代码的结果,但在 C# 中:

E.g. how do I accomplish the result of following Java code, but in C#:

MyClass x = (MyClass) Class.forName("classes.MyChildClass").newInstance();

推荐答案

查看 csharp-examples.net/反射示例.基本上你必须使用 typeof()Activator.createInstance().

Look at csharp-examples.net/reflection-examples. Basically you have to use typeof() and Activator.createInstance().

这篇关于Class.forName() 在 .NET 中等效吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆