Why can't I declare C# methods virtual and static?
Posted
by Luke
on Stack Overflow
See other posts from Stack Overflow
or by Luke
Published on 2008-10-29T20:17:40Z
Indexed on
2010/04/08
2:43 UTC
Read the original article
Hit count: 462
I have a helper class that is just a bunch of static methods and would like to subclass the helper class. Some behavior is unique depending on the subclass so I would like to call a virtual method from the base class, but since all the methods are static I can't create a plain virtual method (need object reference in order to access virtual method).
Is there any way around this? I guess I could use a singleton.. HelperClass.Instance.HelperMethod() isn't so much worse than HelperClass.HelperMethod(). Brownie points for anyone that can point out some languages that support virtual static methods.
Edit: OK yeah I'm crazy. Google search results had me thinking I wasn't for a bit there.
© Stack Overflow or respective owner