public class Base
{
public string getClassName()
{
return this.GetType().Name;
}
}
actually you don't need to create a method getClassName() just to get the type-name. You can call GetType () on any .Net object, and you will get type meta information.
You can also do this,
public class Base
{
}
public class Subclass : Base
{
}
Subclass subclass = new Subclass();
string className = subclass.GetType().Name;
EDIT
, getClassName() , [ .net framework], getClassName() , .
public class Base
{
public string ClassName
{
get
{
return this.GetType().Name;
}
}
}
EDIT2
.
public class Base
{
private string className;
public string ClassName
{
get
{
if(string.IsNullOrEmpty(className))
className = this.GetType().Name;
return className;
}
}
}