Virtual static methods?

  • Thread starter Thread starter Pavils Jurjans
  • Start date Start date
P

Pavils Jurjans

Hello,

I wanted to get some feedback on why there are not allowed virtual static
members in C#.

Say, I have the Parent class, that hosts number of protected methods, that
occasionaly make calls to the virtual methods. When I create the Child
class, inheritting from the Parent class, and declare all of the Parent's
virtual methods with 'override', so that when these methods are called from
within the Parent protected methods, they would use the code that's in the
Child class.
Now, why should I be not allowed to have similar pattern with static
methods - If I have an instance of the Child class, and I call this
protected metjhod whose code is defined in the Parent class, and this code
makes call to this static method, why can't I override the static method
that is called in this scenario, so that the code that resides in the Child
class is called?

Rgds,

Pavils
 
Hi Pavlis,

This has been discussed in this ng several times. You can search google for
those discusion.
Anyways in order polymorphism to work you have to have isntance to an
object. With static method you don't have. This is platform issue. Some
languages (such as Delphi I believe) can do that because for each type there
meta type and there is single instance of it. .NET Type objects are not the
same
 
Stoitcho said:
Hi Pavlis,

This has been discussed in this ng several times. You can search google for
those discusion.
Anyways in order polymorphism to work you have to have isntance to an
object. With static method you don't have. This is platform issue. Some
languages (such as Delphi I believe) can do that because for each type there
meta type and there is single instance of it. .NET Type objects are not the
same

Delphi for .NET supports virtual class methods and metaclasses, but they
are implemented by the compiler with nested classes and other sneaky tricks.

Jesse
 

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

Back
Top