accessibility error

  • Thread starter Thread starter Steven Quail
  • Start date Start date
S

Steven Quail

Hi to all,

I am trying to get the hang of using interfaces and for some reason I
am getting
the "inconsistent 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.
 
Steven Quail said:
I am trying to get the hang of using interfaces and for some reason I
am getting
the "inconsistent accessibility where property ... is less accessible
than property ...(cs0052)".

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.)
 
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.
 
Steven Quail said:
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 :

<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.
 
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.
 
Back
Top