Interface and static properties

P

Paul Selormey

I have looked through the documents but could not find
any information on this. Is anything like static properties
in interfaces?

If not, how do I define property in interface to be made
static property in an abstract base class implementing
the property?

The problem is, I have a lot of interfaces in a library project and
will wish most uses of the library classes should be through
these interfaces and also access to static fields
in the interface. Java allows static fields in interfaces but
..NET does and I was trying to see if property could help.
Any idea?

Best regards,
Paul.
 
N

Nicholas Paldino [.NET/C# MVP]

Paul,

You can not add members to an interface. Also, interfaces do not
support static properties, as interfaces are limited to the instance, not to
the type itself.

I would recommend using an abstract class if you want to do this,
instead of using an interface.

Hope this helps.
 
P

Paul Selormey

Hello Nicholas,
Thanks for the response. I was hoping there is some
trick or work around the problem, so that I will not
have to force use of abstract classes here and there.

Again, thanks for the information.
Best regards,
Paul.

Nicholas Paldino said:
Paul,

You can not add members to an interface. Also, interfaces do not
support static properties, as interfaces are limited to the instance, not to
the type itself.

I would recommend using an abstract class if you want to do this,
instead of using an interface.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Paul Selormey said:
I have looked through the documents but could not find
any information on this. Is anything like static properties
in interfaces?

If not, how do I define property in interface to be made
static property in an abstract base class implementing
the property?

The problem is, I have a lot of interfaces in a library project and
will wish most uses of the library classes should be through
these interfaces and also access to static fields
in the interface. Java allows static fields in interfaces but
.NET does and I was trying to see if property could help.
Any idea?

Best regards,
Paul.
 

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