Get the name of an enum or class string without namespace?
So, I would like to get the name of an enum or class without the full namespace appended to it in front ... For example:
enum MyEnum {
// enum values here
}
// somewhere else in the code
string testString = ???? // ???? returns "MyEnum"
typeof(MyEnum)
basically works, however the enum namespace is added to the front.
Any help would be appreciated ... thanks!
+2
a source to share
1 answer
Use .Name
to get only the type in the string, e.g .:
string testString = typeof(MyEnum).Name;
Here are some examples:
typeof(String).Name // "String"
typeof(String).FullName // "System.String"
.FullName
as in the above example gives the fully qualified name of the type including the namespace.
+8
a source to share