I have a method that I specify to be of a certain type.
Eg
public MyLabels GetLabels<T>()
{
// I'd like to get the namespace of the type that T represents here
}
How can I do this?
typeof(T).FullName // namespace and class name
typeof(T).Namespace // namespace, no class name
You can use typeof(T).FullName
.
That string contains both the class name and the namespace.
怎么样
typeof(T).Namespace;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.