Re: static methods in an interface

Peter Osucha <[email protected]>
Newsgroups gmane.comp.windows.devel.dotnet.cx
Message-ID <[email protected]>
Thanks, Peter, for that explanation.

What I was trying to do was to force some classes marked 'internal' in a
project to all support the same methods.  I guess I'll do some rethinking...

Peter


> -----Original Message-----
> From: Discussion relating to the specifics of the C# and
> Managed C++ languages [mailto:[email protected]]
> On Behalf Of Peter Ritchie
> Sent: Thursday, August 24, 2006 4:33 PM
> To: [email protected]
> Subject: Re: [DOTNET-CX] static methods in an interface
>
> An interface is a definition of what a class instance should
> make publicly available.  Since an instance is not static,
> you cannot declare static members in an interface.
>
> Also, since static members are not in any virtual table
> because they are not related to any particular instance, you
> cannot make a static member virtual--ergo you cannot mandate
> a class to implement specific static members to fulfil derivation.
>
> On Thu, 24 Aug 2006 15:10:12 -0400, Peter Osucha
> <[email protected]> wrote:
>
> >I have an interface defined with some methods.  I have two
> classes that
> >implement this interface - however, I want the classes to
> implement the
> >methods statically.
> >
> >I tried setting the method definition to 'static' in the
> interface but
> >apparently, that's not allowed (I get an error 'The modifier
> 'static'
> >is
> not
> >allowed for this item').
> >
> >If I just try to use the 'static' modifier in the class that
> implements
> the
> >interface, I get another error telling me that the class does not
> implement
> >the interface method (which doesn't have the 'static'
> modifier).  What
> >is going on here and why am I not allowed to create a
> 'static' method
> >this
> way?
> >How might I accomplish what I am trying to do, please?

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.