public class A { public static Type Method() { return /*Получить тип класса*/; } } public class B : A { } public void Test() { Console.WriteLine(A.Method().ToString()); Console.WriteLine(B.Method().ToString()); } 
  • no, maximum you can get A - Grundy
  • The method is static and that it is one for all instances and types. - Monk
  • why ? Maybe you need a non-static method - Grundy
  • It's hard to explain my code like this - Dmitry Chistik

1 answer 1

For a static method, this can not be done. Let's look at the IL code of the Test method:

 IL_0000: nop IL_0001: call UserQuery+A.Method IL_0006: callvirt System.Object.ToString IL_000B: call System.Console.WriteLine IL_0010: nop IL_0011: call UserQuery+A.Method IL_0016: callvirt System.Object.ToString IL_001B: call System.Console.WriteLine IL_0020: nop IL_0021: ret 

It can be seen that in both cases the A.Method method is A.Method : since the method is static, its instructions will be placed in memory in a single instance during type A initialization.

  • Now you saddened me = (. Well, thanks anyway. - Dmitry Chistik