Interface and static properties

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Paul Selormey

    #1

    Interface and static properties

    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.

  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Interface and static properties

    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]
    - mvp@spam.guard. caspershouse.co m

    "Paul Selormey" <paul@toolscent er.org> wrote in message
    news:%230LPMRCt DHA.2136@TK2MSF TNGP10.phx.gbl. ..[color=blue]
    > 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.
    >[/color]


    Comment

    • Paul Selormey

      #3
      Re: Interface and static properties

      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 [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote in
      message news:%23coFzYCt DHA.1196@TK2MSF TNGP12.phx.gbl. ..[color=blue]
      > Paul,
      >
      > You can not add members to an interface. Also, interfaces do not
      > support static properties, as interfaces are limited to the instance, not[/color]
      to[color=blue]
      > 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]
      > - mvp@spam.guard. caspershouse.co m
      >
      > "Paul Selormey" <paul@toolscent er.org> wrote in message
      > news:%230LPMRCt DHA.2136@TK2MSF TNGP10.phx.gbl. ..[color=green]
      > > 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.
      > >[/color]
      >
      >[/color]

      Comment

      Working...