So, I'd like to get the name of an enumeration or class without the full namespace appended on to the front of it... For example:
enum MyEnum {
// enum values here
}
// somewhere else in the code
string testString = ???? // ???? returns "MyE开发者_StackOverflownum"
typeof(MyEnum)
mostly works, however the namespace of the enumeration is appended to the front.
Any help would be appreciated... thanks!
Use .Name
to get only the type in the string, like this:
string testString = typeof(MyEnum).Name;
Here's some examples:
typeof(String).Name // "String"
typeof(String).FullName // "System.String"
.FullName
like the example above gives the full type name, including the namespace.
精彩评论