c# - How to implement an interface explicitly with a virtual method? -
i can't this
interface interfacea { void methoda(); } class classa : interfacea { virtual void interfacea.methoda() // error: modifier 'virtual' not valid item { } }
where following works
class classa : interfacea { public virtual void methoda() { } }
why? how circumvent this?
i think because when member explicitly implemented, cannot accessed through class instance, through instance of interface.
so making 'virtual' not make sense in case, since virtual means intend override in inherited class. implementing interface explicitly and making virtual contradictory. may why compiler disallows this.
to work around think csharptest.net's or philip's answer sounds trick
Comments
Post a Comment