我想得到一个枚举或类的名称,前面没有完整的名称空间。。。例如:
enum MyEnum { // enum values here } // somewhere else in the code string testString = ???? // ???? returns "MyEnum"
typeof(MyEnum)
任何帮助都将不胜感激。。。谢谢!
使用 .Name 仅获取字符串中的类型,如下所示:
.Name
string testString = typeof(MyEnum).Name;
以下是一些示例:
typeof(String).Name // "String" typeof(String).FullName // "System.String"
.FullName 像上面的例子一样,给出了完整的类型名,包括名称空间。
.FullName