Calling Class and Static

  • Thread starter msnews.microsoft.com
  • Start date
M

msnews.microsoft.com

In the following classes ... it is possible when calling

MyDerived.Test()

to know that I am calling Test from MyDerived and NOT from MyClass?!

I have tried MethodInfo.GetCurrentMethod().ReflectedType ... but that
returns back MyClass.


public class MyClass
{


public static string Test()
{

}

}

public class MyDerived : MyClass
{


}




MyDerived.Test();
 
J

Jon Skeet [C# MVP]

msnews.microsoft.com said:
In the following classes ... it is possible when calling

MyDerived.Test()

to know that I am calling Test from MyDerived and NOT from MyClass?!

No. It actually gets compiled to a call to MyClass.Test anyway.
 
M

msnews.microsoft.com

Ahh ... good point. i hadn't thought of checking out the generated code ...

Thanks!

Brett
 
M

msnews.microsoft.com

Yea ... I had thought of that, but here are the results

at MyClass.Test()
at MyClass.Main()

Brett
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top