How to get the current class name at runtime? [duplicate]

半世苍凉 提交于 2019-12-05 16:18:38

问题


I'm trying to get a current class name into a string.

For example:

public class Marker : Mark
{
    string currentclass = ???;
}

public abstract class MiniMarker : Mark
{
}

I'd like to get the string from Marker class so I do not have to put it inside each abstract class I make from it.

I want the string to be MiniMarker, or what ever the abstract class is named.

I tried MethodBase.GetCurrentMethod().DeclaringType, but it did not work.


回答1:


   this.GetType().Name

should return a Class name




回答2:


This should do:

this.GetType().ToString()


来源:https://stackoverflow.com/questions/12035426/how-to-get-the-current-class-name-at-runtime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!