创建Console工程名为:NamespaceRef
具体代码如下:using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;namespace NamespaceRef
{
class Program
{
static void Main(string[] args)
{
Country cy;
String assemblyName = @"NamespaceRef";
string strongClassName = @"NamespaceRef.China";
// 注意:这里类名必须为强类名
// assemblyName可以通过工程的AssemblyInfo.cs中找到
cy = (Country)Assembly.Load(assemblyName).CreateInstance(strongClassName);
Console.WriteLine(cy.name);
Console.ReadKey();
} class Country
{
public string name;
} class Chinese : Country
{
public Chinese()
{
name = "你好";
}
} class America : Country
{
public America()
{
name = "Hello";
}
}
}
}
这句话
cy = (Country)Assembly.Load(assemblyName).CreateInstance(strongClassName);
没有创建实例么?
为什么没有创建呢?
具体代码如下:using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;namespace NamespaceRef
{
class Program
{
static void Main(string[] args)
{
Country cy;
String assemblyName = @"NamespaceRef";
string strongClassName = @"NamespaceRef.China";
// 注意:这里类名必须为强类名
// assemblyName可以通过工程的AssemblyInfo.cs中找到
cy = (Country)Assembly.Load(assemblyName).CreateInstance(strongClassName);
Console.WriteLine(cy.name);
Console.ReadKey();
} class Country
{
public string name;
} class Chinese : Country
{
public Chinese()
{
name = "你好";
}
} class America : Country
{
public America()
{
name = "Hello";
}
}
}
}
这句话
cy = (Country)Assembly.Load(assemblyName).CreateInstance(strongClassName);
没有创建实例么?
为什么没有创建呢?
Assembly.Load("程序集").CreateInstance("命名空间.类")
参考