0

I wanted to dynamically load classes in C#. I remember in Java we used Class.forname("String") , so after googling I found out that we could use Activator.CreateInstance in C# . I cannot figure out what my assembly name would be here. Any suggestions ?

object obj = Activator.CreateInstance("MyAssembly","namespaceA.SomeClassName");
4

1 に答える 1

1

It's simply the name of the assembly. That might be the same as the namespace, but it might not. For example, the System.Linq.Enumerable class is in the System.Core assembly (in System.Core.dll).

If the target assembly is a framework one, look at the documentation.

If it's one that's under your control, you should know the assembly name - it's part of the project properties.

于 2012-11-13T17:45:37.947 に答える