获取类型的名称,而不在C#中完整的命名空间 [英] Get type name without full namespace in C#
本文介绍了获取类型的名称,而不在C#中完整的命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码:
回归[插入新的+ typeof运算(T)的ToString()+ ];
但
的typeof(T)的ToString()
返回的全名,包括名字空间。
反正是有先手类名(没有任何名字空间限定符?)
解决方案
的typeof(T).Name点//类名,没有命名空间
的typeof(T).FullName //命名空间和类名
的typeof(T)。命名空间//命名空间,类名
I have the following code:
return "[Inserted new " + typeof(T).ToString() + "]";
But
typeof(T).ToString()
returns the full name including namespace
Is there anyway to just get the class name (without any namespace qualifiers?)
解决方案
typeof(T).Name // class name, no namespace
typeof(T).FullName // namespace and class name
typeof(T).Namespace // namespace, no class name
这篇关于获取类型的名称,而不在C#中完整的命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文