我有以下课程:
class MyClass{
{
Run Code Online (Sandbox Code Playgroud)
和以下字符串:
string s="MyClass";
Run Code Online (Sandbox Code Playgroud)
如何使用字符串s获取类的类型:
Type t = typeof(MyClass); //but i need to use s instead.
Run Code Online (Sandbox Code Playgroud)
我已经尝试过了
Type type = Type.GetType(s); //the result is null
Run Code Online (Sandbox Code Playgroud)
与googeling我发现了这个
Type type = Type.GetType(完全限定类名字符串);
来自msdn:
typeName:要获取的类型的程序集限定名称.请参阅AssemblyQualifiedName.如果类型在当前正在执行的程序集中或在Mscorlib.dll中,则提供由其名称空间限定的类型名称就足够了.
返回值具有指定名称的类型(如果找到); 否则,nullNothingnullptra null引用(在Visual Basic中没有任何内容).
所以,...我相信当你得到null作为结果时找不到它
要了解您的完全限定名称
typeof(MyClass).FullName
typeof(MyClass).AssemblyQualifiedName
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6725 次 |
| 最近记录: |