In the Code below:
string GetName(Type type)
{
return ((type)this.obj).Name;
}
void Run()
{
string name = GetName(typeof(MyClass));
}
Im getting a “The type or name space cannot be found (are you missing using a directive or assembly reference?)” error. What should I do to correct this?
You can’t cast to an instance !
type is a instance of the Type class, if you want to cast to certain Type, use Generics
then you can call
If that makes sens.