C
cody
Often you want to get the type of the current class in a static method.
since in static methods you cannot call GetType(), you have to go for
typeof(MyClass). But the problem now is, that this does not make the intend
really clear that you mean the "current class".
I you have to refactor your code, move this method or rename the class you
will run into problems.
Thats why i suggest a new language feature: "typeof (class)". since class
is
already a keyword, no new keywords are needed. What do you think?
public class MyClass
{
public static DoIt()
{
Console.WriteLine("Iam declared in class: " + typeof (class));
}
}
since in static methods you cannot call GetType(), you have to go for
typeof(MyClass). But the problem now is, that this does not make the intend
really clear that you mean the "current class".
I you have to refactor your code, move this method or rename the class you
will run into problems.
Thats why i suggest a new language feature: "typeof (class)". since class
is
already a keyword, no new keywords are needed. What do you think?
public class MyClass
{
public static DoIt()
{
Console.WriteLine("Iam declared in class: " + typeof (class));
}
}