Interface and static properties

  • Thread starter Thread starter Paul Selormey
  • Start date Start date
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.
 
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.
 
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.
 
Back
Top