accessibility error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steven Quail

    #1

    accessibility error

    Hi to all,

    I am trying to get the hang of using interfaces and for some reason I
    am getting
    the "inconsiste nt accessibility where property ... is less accessible
    than property ...(cs0052)".

    What I have is the following:
    (sorry if the syntax is incorrec)

    IAddress =
    {
    string Number;
    string Street;
    }

    IAddressList =
    {
    IAddress CurrentAddress {get;}
    void FirstAddress();
    void NextAddress();
    bool HasAddress();
    }


    When I implement IAddressList in a class, I get the accessibility
    error.
    Note that when I change IAddress CurrentAddress {get;} for
    Object CurrentAddress{ get;} I do not get the error.

    The class that implements IAddressList only implements this interface.
    i.e.
    public class AddressList : IAddressList {...}

    Any help would be greatly appreciated.

    Steven.
  • Jon Skeet

    #2
    Re: accessibility error

    Steven Quail <squail71@yahoo .com> wrote:[color=blue]
    > I am trying to get the hang of using interfaces and for some reason I
    > am getting
    > the "inconsiste nt accessibility where property ... is less accessible
    > than property ...(cs0052)".[/color]

    You basically need to make your implementation have the same access
    (public, internal, protected) as your interface. (The class itself
    doesn't have to have the same access, but the bits which implement the
    interface do.)

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    • Steven Quail

      #3
      Re: accessibility error

      Thank you very much Jon for the reply.

      What I remember (I am doing C# at home and at work Delphi) is that my class
      that implements the interfaces was defined as :

      public class AddressList : IAddressList
      {
      ....

      public IAddress CurrentAddress
      {
      get
      {
      return ....;
      }
      }

      }

      When you said that the class implementing the interface must have the same
      access, is the above correct given that my interface is given as:

      IAddress =
      {
      string Number;
      string Street;
      }

      IAddressList =
      {
      IAddress CurrentAddress {get;}
      void FirstAddress();
      void NextAddress();
      bool HasAddress();
      }


      I thought that interfaces did not have access specifiers?? (I definately
      have lots to learn).

      Thanks
      Steven.



      Jon Skeet <skeet@pobox.co m> wrote in message news:<MPG.19b68 2c08ec00d3598a3 aa@news.microso ft.com>...[color=blue]
      > Steven Quail <squail71@yahoo .com> wrote:[color=green]
      > > I am trying to get the hang of using interfaces and for some reason I
      > > am getting
      > > the "inconsiste nt accessibility where property ... is less accessible
      > > than property ...(cs0052)".[/color]
      >
      > You basically need to make your implementation have the same access
      > (public, internal, protected) as your interface. (The class itself
      > doesn't have to have the same access, but the bits which implement the
      > interface do.)[/color]

      Comment

      • Jon Skeet

        #4
        Re: accessibility error

        Steven Quail <squail71@yahoo .com> wrote:[color=blue]
        > Thank you very much Jon for the reply.
        >
        > What I remember (I am doing C# at home and at work Delphi) is that my class
        > that implements the interfaces was defined as :[/color]

        <snip>

        It would help if you could post the *real* code - or preferrably a
        short but complete example which demonstrates the problem. See
        http://www.pobox.com/~skeet/csharp/complete.html for what I mean by
        that.

        Here's a short but complete example which *does* compile:

        using System;

        public class AddressList : IAddressList
        {
        public string CurrentAddress
        {
        get
        {
        return null;
        }
        }

        static void Main()
        {
        }
        }

        interface IAddressList
        {
        string CurrentAddress {get;}
        }

        I suggest you take a copy of your existing code, rip out all the bits
        which are unrelated to this (ie almost everything) and when you've got
        an example which is about the size of the above but which doesn't
        compile, post it.

        --
        Jon Skeet - <skeet@pobox.co m>
        Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

        If replying to the group, please do not mail me too

        Comment

        • Steven Quail

          #5
          Re: accessibility error

          Hi to all,

          Thank you Jon for your input. Took your advise and created a demo app and
          got the same error.

          So now I have isolated the problem down to the definition of the interface.

          Then realised that I was not putting a public access modifier in front of
          the interface declaration. Coming from a Delphi background, declarations
          for interfaces do not have access modifiers.

          Anyway, that resolved the problem.

          Thank you for all you help

          Steven.


          Jon Skeet <skeet@pobox.co m> wrote in message news:<MPG.19b6d 05c929c1efe98a3 b3@news.microso ft.com>...[color=blue]
          > Steven Quail <squail71@yahoo .com> wrote:[color=green]
          > > Thank you very much Jon for the reply.
          > >
          > > What I remember (I am doing C# at home and at work Delphi) is that my class
          > > that implements the interfaces was defined as :[/color]
          >
          > <snip>
          >
          > It would help if you could post the *real* code - or preferrably a
          > short but complete example which demonstrates the problem. See
          > http://www.pobox.com/~skeet/csharp/complete.html for what I mean by
          > that.
          >
          > Here's a short but complete example which *does* compile:
          >
          > using System;
          >
          > public class AddressList : IAddressList
          > {
          > public string CurrentAddress
          > {
          > get
          > {
          > return null;
          > }
          > }
          >
          > static void Main()
          > {
          > }
          > }
          >
          > interface IAddressList
          > {
          > string CurrentAddress {get;}
          > }
          >
          > I suggest you take a copy of your existing code, rip out all the bits
          > which are unrelated to this (ie almost everything) and when you've got
          > an example which is about the size of the above but which doesn't
          > compile, post it.[/color]

          Comment

          Working...